Code: Select all
If InitMouse()=0 Or InitSprite()=0 Or InitSprite3D()=0 Or InitKeyboard()=0
MessageRequester("Error","Can't access DirectX",0):End
EndIf
OpenScreen(1024,768,32,"Sistema de coordenadas ortogonales cartesianas")
CreateSprite(1,512,512,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1)):BackColor(0,0,0)
Line(Int(512/2),0,0,511,$AAAAAA)
Line(Int(512/2-1),0,0,511,$AAAAAA)
Line(0,Int(512/2),511,0,$AAAAAA)
Line(0,Int(512/2-1),511,0,$AAAAAA)
StopDrawing()
S3DR_CreateZBuffer()
Start3D()
S3DR_BeginReal3D()
S3DR_MoveCamera(0,0,-4)
S3DR_UseTransparency(#S3DR_TRUE)
S3DR_SetCullMode(#S3DR_NONE)
;Create the system:
S3DR_StartCreateMesh()
S3DR_CreateMesh_AddQuad(-1,1,0,1,1,0,-1,-1,0,1,-1,0);<- Plano xy (plano atravesado ortogonalmente por el eje z)
S3DR_CreateMesh_AddQuad(1,1,0,-1,1,0,1,-1,0,-1,-1,0);<- Plano xy visto por detrás
S3DR_CreateMesh_AddQuad(-1,0,1,1,0,1,-1,0,-1,1,0,-1);<- Plano xz (plano atravesado ortogonalmente por el eje y)
S3DR_CreateMesh_AddQuad(1,0,1,-1,0,1,1,0,-1,-1,0,-1);<- Plano xz visto por detrás
S3DR_CreateMesh_AddQuad(0,1,1,0,1,-1,0,-1,1,0,-1,-1);<- Plano yz (plano atravesado ortogonalmente por el eje x)
S3DR_CreateMesh_AddQuad(0,1,-1,0,1,1,0,-1,-1,0,-1,1);<- Plano yz visto por detrás
sys.l=S3DR_StopCreateMesh()
S3DR_EndReal3D()
Stop3D()
Sprite3DQuality(1)
axis.b=1
;-MAIN:
Repeat
ExamineKeyboard()
ExamineMouse()
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer($000000)
S3DR_UseTransparency(#S3DR_TRUE)
S3DR_SetCullMode(#S3DR_NONE)
S3DR_SelectTexture(1)
If MouseButton(2)
While MouseButton(2):Delay(20):ExamineMouse():Wend
axis.b+1:If axis.b>=4:axis.b=1:EndIf
EndIf
StartDrawing(ScreenOutput()):Locate(0,0):DrawText(Chr($57+axis.b)+" axis"):StopDrawing()
StartDrawing(ScreenOutput()):Locate(0,0)
Select axis.b
Case 1
If MouseButton(1):DrawText("Now rotating over X axis"):angleX.f+0.02:EndIf; <- rotate over X axis of the world ?
angleY.f-MouseDeltaX()/500:angleZ.f-MouseDeltaY()/500
Case 2
If MouseButton(1):DrawText("Now rotating over Y axis"):angleY.f+0.02:EndIf; <- rotate over Y axis of the world ?
angleZ.f-MouseDeltaX()/500:angleX.f-MouseDeltaY()/500
Case 3
If MouseButton(1):DrawText("Now rotating over Z axis"):angleZ.f+0.02:EndIf; <- rotate over Z axis of the world ?
angleY.f-MouseDeltaX()/500:angleX.f-MouseDeltaY()/500
EndSelect
StopDrawing()
S3DR_DrawMesh(sys.l,0,0,0,angleX,angleY,angleZ);,1,1,1)
If KeyboardPushed(#PB_Key_R):angleX=0:angleY=0:angleZ=0:EndIf
If KeyboardPushed(#PB_Key_Up) :S3DR_MoveCamera(0,0,0.04):EndIf
If KeyboardPushed(#PB_Key_Down):S3DR_MoveCamera(0,0,-0.04):EndIf
S3DR_EndReal3D()
Stop3D()
FlipBuffers():Delay(16)
Until KeyboardPushed(#PB_Key_Escape)
S3DR_FreeMesh(sys.l); Don't forget to free the Mesh.
CloseScreen()
Note that when rotating over Z axis the Z axis OF THE MESH doesn't move, only rotates over itself. But when rotating over X axis or Y axis things are different.