another experiment, i will use a sphere made from circles which are made from points like this:
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
Quit.b = #False
rot.l=1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=0.5:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 1.8: depth.f=0
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), " sphere from circles ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)
InitKeyboard()
SetFrameRate(60)
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))
CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)
RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
;SkyDome("clouds.jpg", 100) ;for blue color background
;- Mesh
CreateTexture(0,32,32)
StartDrawing(TextureOutput(0))
Box(0,0,32,32,RGB(255,255,255))
StopDrawing()
CreateMaterial(0,TextureID(0))
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
DisableMaterialLighting(0, #True)
SetMeshMaterial(1, MaterialID(0))
x.f: y.f :z.f : u.f: v.f: r.f
majorOrbit.l = 100 : minorOrbit.l = 100
majorStep.f = 2 * #PI / majorOrbit
minorStep.f = 2 * #PI / minorOrbit
i.l: j.l
For i = 0 To 100
u = i * majorStep
For j = 0 To minorOrbit
v = j * minorStep
r = 4 * (1 - (Cos(u)/2))
x = Cos(u) * Cos(v)
y = Sin(u) * Cos(v)
z.f = Sin(v)
MeshVertexPosition(x, y, z);
MeshVertexColor(RGB(0,255,0))
Next
Next
NormalizeMesh(1)
FinishMesh(#True)
CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,3, 3, 3)
;Main loop
MoveEntity(1,0,up,depth,#PB_Absolute)
x = 180: y=0: z=0 : h.f
Repeat
Event = WindowEvent()
x + rotx
y + roty
z + rotz
RotateEntity(1, x, y, z)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
and then attach triangles between the points on every circle and the points on the next circle then make texturing, i have copied the procedure from my previous klein and mobius examples, so the texturing are not correct and flicker , but the purpose is to show that morphing speed are good even on the huge number of vertices (here it is 1500 ) and that depends on the heavy usage of sin,cos,tan etc functions. you can try other morphing equations.
the morphing are inside morph() procedure ,press W to toggle wire/solid
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
Declare morph()
Global Epsilon2.f = 5
Global Epsilon1.f = 1
Global amplitude.f = 5
Global freq.f = 1.0
Quit.b = #False : wireFrame.b = 1
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=0.5:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 1.8: depth.f=0
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale mesh..Arrows for rotation, space: stop/rotate, QA far/near, key_pad R/L/U/D", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop")
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)
;WorldShadows(#PB_Shadow_Additive)
InitKeyboard()
SetFrameRate(60)
Add3DArchive("/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))
CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)
RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
SetActiveGadget(#BUTTON)
;SkyDome("clouds.jpg", 100) ;for blue color background
;- Mesh
CreateMaterial(0, LoadTexture(0, "terrain_texture.jpg"))
MaterialShadingMode(0, #PB_Material_Wireframe)
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
DisableMaterialLighting(0, #True)
SetMeshMaterial(1, MaterialID(0))
node = CreateNode(#PB_Any)
AttachNodeObject(node, MeshID(1))
ScaleNode(node, 1, 1, 1)
x.f: y.f :z.f : u.f: v.f: r.f
majorOrbit.l = 50 : minorOrbit.l = 30
majorStep.f = 2 * #PI / majorOrbit
minorStep.f = 2 * #PI / minorOrbit
i.l: j.l :txu.f : txv.f
For i = 0 To majorOrbit
v = i * majorStep
For j = 0 To minorOrbit
u = j * minorStep
r = 4 * (1 - (Cos(u)/2))
x = Cos(u) * Cos(v)
y = Sin(u) * Cos(v)
z.f = Sin(v)
MeshVertexPosition(x, y, z);
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(x, y, z)
;texture the whole sphere with one picture stretched
txv = txv + 1/minorOrbit ;
Next
txv = 0
txu = txu + 1/majorOrbit
Next
;vv.l = MeshVertexCount(1,0)
t=0
For i = 0 To majorOrbit-1
For j = 0 To minorOrbit
MeshFace(t,t+1,t + minorOrbit+1)
MeshFace(t + minorOrbit+1,t + minorOrbit+2,t+1 )
If i=majorOrbit-1 And j=minorOrbit-1 ;bypass the last triangle
minorOrbit-1
EndIf
t + 1
Next
Next
NormalizeMesh(1)
FinishMesh(#False)
;Debug MeshVertexCount(1,0)
;Main loop
MoveNode(node,0,up,depth,#PB_Absolute)
x = 180: y=0: z=0 : h.f
Repeat
Event = WindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #BUTTON
If rot = 0
rot = 1
rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
stopFlag = 1
Else
rot = 0
rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
rotx=0:roty=0:rotz=0
stopFlag = 0
EndIf
EndSelect
EndIf
If stopFlag=1
x + rotx
y + roty
z + rotz
EndIf
morph()
RotateNode(node, x, y, z)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) ; rotate left
rotx=1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Down) ; rotate right
rotx=-1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Right) ; rotate up
rotx=0:roty=1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Left) ; rotate down
rotx=0:roty=-1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
EndIf
If KeyboardPushed(#PB_Key_PageUp) ; scale up model
xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
ScaleNode(node,xs,ys,zs)
ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
xs = 0.9:ys = 0.9:zs= 0.9
ScaleNode(node,xs,ys,zs)
ElseIf KeyboardReleased(#PB_Key_W) ; display wire frame for the material
If wireFrame=0
MaterialShadingMode(0, #PB_Material_Wireframe)
wireFrame ! 1
ElseIf wireFrame=1
MaterialShadingMode(0, #PB_Material_Solid)
wireFrame ! 1
EndIf
EndIf
If KeyboardPushed(#PB_Key_Pad8) ; up move
up + 0.1
MoveNode(node,h,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Pad2) ; down move
up - 0.1
MoveNode(node,h,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Pad6)
h + 0.1
MoveNode(node,h,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Pad4)
h - 0.1
MoveNode(node,h,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Q) ; forward move
depth - 0.1
MoveNode(node,h,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_A) ; inward move
depth + 0.1
MoveNode(node,h,up,depth,#PB_Absolute)
EndIf
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
Procedure morph()
x.f: y.f :z.f : u.f: v.f: r.f
majorOrbit.l = 50 : minorOrbit.l = 30
majorStep.f = 2 * #PI / majorOrbit
minorStep.f = 2 * #PI / minorOrbit
i.l: j.l :txu.f : txv.f
UpdateMesh(1, 0)
;warping a sphere
;dtime.f=ElapsedMilliseconds()/1200
;--------------------------------
;morphing equations:
;--------------------------------
;vx.f = amplitude * Sin(dtime*freq)
;vy.f = amplitude * Cos(dtime*freq)
;vz.f = amplitude * Sin(dtime*freq)
For i = 0 To majorOrbit
v = i * majorStep
For j = 0 To minorOrbit
u = j * minorStep
;r = 4 * (1 - (Cos(u)/2))
dtime.f=ElapsedMilliseconds()/1200
;--------------------------------
;morphing equations:
;--------------------------------
vx.f = amplitude * Sin(dtime*freq)
vy.f = amplitude * Cos(dtime*freq)
vz.f = amplitude * Sin(dtime*freq)
x = Cos(u) * Cos(v) *vx
y = Sin(u) * Cos(v) *vy
z.f = Sin(v) *vz
MeshVertexPosition(x, y, z);
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(x, y, z)
;texture the whole sphere with one picture stretched
txv = txv + 1/minorOrbit ;
Next
txv = 0
txu = txu + 1/majorOrbit
Next
;vv.l = MeshVertexCount(1,0)
t=0
For i = 0 To majorOrbit-1
For j = 0 To minorOrbit
MeshFace(t,t+1,t + minorOrbit+1)
MeshFace(t + minorOrbit+1,t + minorOrbit+2,t+1 )
If i=majorOrbit-1 And j=minorOrbit-1 ;bypass the last triangle
minorOrbit-1
EndIf
t + 1
Next
Next
NormalizeMesh(1)
FinishMesh(#False)
EndProcedure