here is how to draw a textured animated 3D curves, it depends on the MP3D ability to change dynamically the model vertices coordinates even the real models such as 3ds models. i have used as a template the example by Michael "MP_Bewegende Objekte.pb" from the MP3D library examples\mesh.
i have used a plane 30x30 so it has 961 vertices (31x31). the plot range for the first example is from -3 ro +3 so we need to project the real plot to the 30x30 plane. we just multiply the x,y vertices of the plane by 6/30.
the first example will plot a curve resemble a flying carpet textured by a tiger fur. save the texture from here
http://s13.postimage.org/b88odkv3r/tiger.png to the program folder. you can tune the figure by changing the timer values, or more or less z values.
Code: Select all
;//published originally by Michael Paulwitz as the library example "MP_Bewegende Objekte.pb"
;//used and modified here to draw a 3D curve
MP_Graphics3D (640,480,0,3) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "3D animated curves _ use arrow keys to rotate,..... z, x to zoom in/out") ; So soll es heissen
camera=MP_CreateCamera() ; Kamera erstellen
camX.f=0 : camY.f=0 : camZ.f = -40 : rotX=0: rotY=45
Global timer.l: Global tX.f,tY.f,tZ.f
tX=-3.2:tY=-3
MP_PositionCamera(camera,camX,camY,camZ)
light=MP_CreateLight(2)
light2=MP_CreateLight(2)
MP_LightSetColor(light,RGB(255,255,255))
MP_LightSetColor(light2,RGB(255,255,255))
MP_AmbientSetLight (RGB(255,220,255))
MP_PositionEntity(light,0,50,-60)
MP_PositionEntity(light2,0,100,60)
plane=MP_CreatePlane(30,30) ;the plane used for draw
teapot=MP_CreateTeapot() ; just a fantasia
texture = MP_LoadTexture("tiger.png")
;texture = MP_CreateTextureColor(256, 256, RGBA(0, 255, 255, 255))
MP_EntitySetTexture(plane, texture)
MP_MaterialEmissiveColor (texture, 0, 0, 0, 0)
;MP_MaterialSpecularColor(plane,1,255,10,0,1)
For n = 0 To MP_CountVertices(plane)-1
farbea.l = Random(255)
farbeb.l = Random(255)
farbec.l = Random(255)
;uncomment the below line to enable colorfull demo
;MP_VertexSetColor (plane,n,RGB(farbea,farbeb,farbec))
;MP_VertexSetColor (plane,n,RGB(255,100,0))
Next
;MessageRequester("",Str(MP_CountVertices(plane)))
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder schliessen
;play with timer values to tune nore
timer = MP_ElapsedMicroseconds()/200
For n = 0 To MP_CountVertices(plane)-1
x.f = MP_VertexGetX (plane,n)
y.f = MP_VertexGetY (plane,n)
z.f = MP_VertexGetZ (plane,n)
;projecting the draw from -3 to 3 over -15 to 15:
x=x*6/30: y=y*6/30
;zufall.f = (Cos(timer/600+(Pow(x*(6/30),2)+Pow(y*(6/30),2))/4))/(Pow(x,2) + Pow(y,2) + 3.1415/9)
;zufall.f = (Cos(timer/600+(Sqr(Pow(2*x*(6/30),2)+Pow(2*y*(6/30),2)))))
zufall.f = (Sin(timer/100+x)+Sin(timer/100+y))/5
;MP_VertexSetX (plane,n, x + zufall)
;MP_VertexSetY (plane,n, y + zufall)
MP_VertexSetZ (plane,n, z + zufall)
If n=900
zufall.f = (Sin(timer/100+0*(6/30))+Sin(timer/100+(-1)*(6/30)))/5
MP_PositionEntity(teapot,0,z+zufall,-1)
EndIf
Next
If MP_KeyDown(#PB_Key_Up)
rotY+1
ElseIf MP_KeyDown(#PB_Key_Down)
rotY-1
ElseIf MP_KeyDown(#PB_Key_Right)
rotX+1
ElseIf MP_KeyDown(#PB_Key_Left)
rotX-1
ElseIf MP_KeyDown(#PB_Key_Z )
camZ+1
ElseIf MP_KeyDown(#PB_Key_X )
camZ-1
EndIf
MP_RotateEntity(plane, rotX, rotY, 0 )
MP_PositionCamera(camera,camX,camY,camZ)
MP_RenderWorld ()
MP_Flip () ;
Wend
End
if you want to try more functions uncoment one of another 2 functions in the code
the other code resemble the example posted here
http://www.purebasic.fr/english/viewtop ... =7&t=50171 but to plot a textured 3D letter 'A' , save this texture to use :
http://s18.postimage.org/hvzb0h2s9/snake.png
. and the plot are from -1 to +1 so we have to multiply the 30x30 plane x,y by 2/30, there is no timer here since we want to plot only the z values.
Code: Select all
;//published originally by Michael Paulwitz as example "MP_Bewegende Objekte.pb"
;//used and modified here to show textured 3D 'A' letter
MP_Graphics3D (640,480,0,3)
SetWindowTitle(0, "3D animated curves _ use arrow keys to rotate,..... z, x to zoom in/out") ; So soll es heissen
camera=MP_CreateCamera()
camX.f=0 : camY.f=0 : camZ.f = -60 : rotX=0: rotY=0: rotZ=-90
Global timer.l: Global tX.f,tY.f,tZ.f
tX=-3.2:tY=-3
MP_PositionCamera(camera,camX,camY,camZ)
light=MP_CreateLight(2)
MP_LightSetColor(light,RGB(255,255,255))
MP_AmbientSetLight (RGB(255,220,255))
MP_PositionEntity(light,0,50,-60)
plane=MP_CreatePlane(30,30)
tea=MP_CreateTeapot()
texture = MP_LoadTexture("snake.png")
MP_EntitySetTexture(plane, texture)
MP_MaterialEmissiveColor (texture, 0, 0, 0, 0)
;MP_MaterialSpecularColor(plane,1,255,10,0,1)
;MessageRequester("",Str(MP_CountVertices(plane)))
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder schliessen
For n = 0 To MP_CountVertices(plane)-1
x.f = MP_VertexGetX (plane,n)
y.f = MP_VertexGetY (plane,n)
z.f = MP_VertexGetZ (plane,n)
x=x*2/30: y=y*2/30
zufall.f = ((1-Sign(-x-0.9+Abs(y*2)))/3*(Sign(0.9-x)+1)/3)*(Sign(x+0.65)+1)/2 -((1-Sign(-x-0.39+Abs(y*2)))/3*(Sign(0.9-x)+1)/3) + ((1-Sign(-x-0.39+Abs(y*2)))/3*(Sign(0.6-x)+1)/3)*(Sign(x-0.35)+1)/2
MP_VertexSetZ (plane,n, -zufall*40)
Next
If MP_KeyDown(#PB_Key_Up)
rotY+1
ElseIf MP_KeyDown(#PB_Key_Down)
rotY-1
ElseIf MP_KeyDown(#PB_Key_Right)
rotX+1
ElseIf MP_KeyDown(#PB_Key_Left)
rotX-1
ElseIf MP_KeyDown(#PB_Key_Z )
camZ+1
ElseIf MP_KeyDown(#PB_Key_X )
camZ-1
EndIf
MP_RotateEntity(plane, rotX, rotY, rotZ )
MP_PositionCamera(camera,camX,camY,camZ)
MP_RenderWorld ()
MP_Flip () ;
Wend
End
to experiment with more 3D functions look
http://www.benjoffe.com/code/tools/functions3d/examples
i am still studying the MP3D since it is so huge, i just use a small part of it wich deals with vertices for plotting and deforming.
at last where are you Michael !! i hope you are okay.
regards