Ogre3D basic obecjst movement examples?
Ogre3D basic obecjst movement examples?
Is there any examples on how to make simple 3D shapes and also move and rotate the 3D objects ?
I just started using Ogre3D, and there are quite a few Ogre3D functions that are quite nice.
Thank you.
I just started using Ogre3D, and there are quite a few Ogre3D functions that are quite nice.
Thank you.
-
Kelebrindae
- Enthusiast

- Posts: 151
- Joined: Tue Apr 01, 2008 3:23 pm
Re: Ogre3D basic obecjst movement examples?
Hi,
There's no "simple" way to create 3D shapes in PB (no "makeCube" or "createPlane" command)... => it's far simpler to load the needed meshes from external files.
[EDIT] False since PB4.60: CreateCube, CreatePlane, CreateCylinder, CreateSphere are now available!
Still, it's possible to create meshes from scratch. Here's a demo code that shows how to do it:
(it's quite old, so it may be clumsy here and there...
)
[EDIT] updated for PB4.61
There's no "simple" way to create 3D shapes in PB (no "makeCube" or "createPlane" command)... => it's far simpler to load the needed meshes from external files.
[EDIT] False since PB4.60: CreateCube, CreatePlane, CreateCylinder, CreateSphere are now available!
Still, it's possible to create meshes from scratch. Here's a demo code that shows how to do it:
(it's quite old, so it may be clumsy here and there...
[EDIT] updated for PB4.61
Code: Select all
; Author: Kelebrindae (modification of the "cylinder 3D" demo, from Comtois)
; Date: march,13, 2006, last updated 06/06/2012
; PB version: v4.61
; OS: Windows XP
; Demo: Yes
;- Initialisation
Resultat = MessageRequester("Platonic Solids","Full Screen ?",#PB_MessageRequester_YesNo)
If Resultat = 6
FullScreen=1
Else
FullScreen=0
EndIf
If InitEngine3D() = 0
MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 )
End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 )
End
EndIf
If Fullscreen
OpenScreen(800,600,32,"Platonic Solids")
Else
OpenWindow(0,0, 0, 800 , 600 ,"Platonic Solids",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0, 800 , 600,0,0,0)
EndIf
;- Data structures and definitions
Global CameraMode.i
Structure Vertex
px.f
py.f
pz.f
nx.f
ny.f
nz.f
Couleur.i
U.f
V.f
EndStructure
Structure Triangle
f1.w
f2.w
f3.w
EndStructure
Enumeration
#tetrahedron
#cube
#octahedron
#dodecahedron
#icosahedron
EndEnumeration
EnableExplicit
;- ---- Procedures ----
;************************************************************************************
; Name: CreatePlatonicMesh
; Purpose: Create a platonic solid mesh, scaled and UV mapped dynamically
; Parameters:
; - solide: #tetrahedron,#cube,#octahedron,#dodecahedron, or #icosahedron
; - X size
; - Y size
; - Z size
; - origin of mapping coord U
; - origin of mapping coord V
; - Vertices color
; Return value: mesh number, or -1 if an error occurs
;************************************************************************************
Procedure.i CreatePlatonicMesh(solid.i,sizeX.f = 1,sizeY.f = 1,sizeZ.f = 1,Uorigin.f = 0,Vorigin.f = 0,Uscale.f = 1,Vscale.f = 1,color.i = $FFFFFF)
Protected nbVert.i , nbTri.i ; Number of vertices and faces
Protected x.f,y.f,z.f ; vertex position
Protected nx.f,ny.f,nz.f ; vertex normals
Protected u.f,v.f ; vertex UV coords (texture mapping)
Protected newmesh.i ; Procedure Result
Protected i.i,v1.i,v2.i,v3.i
; Restore the good set of meshdatas
Select solid
Case #tetrahedron
Restore tetrahedron
Case #cube
Restore cube
Case #octahedron
Restore octahedron
Case #dodecahedron
Restore dodecahedron
Case #icosahedron
Restore icosahedron
Default
ProcedureReturn -1
EndSelect
; Read number of vertices and triangles
Read nbVert
Read nbTri
; Read and store vertices position, normals, uv coords
newMesh = CreateMesh(#PB_Any)
For i = 1 To nbVert
Read.f x
Read.f y
Read.f z
Read.f nx
Read.f ny
Read.f nz
Read.f u
Read.f v
AddMeshVertex(x * sizex,y * sizey,z * sizez)
MeshVertexNormal(nx,ny,nz)
MeshVertexColor(color)
MeshVertexTextureCoordinate(uorigin + (u * uscale),vorigin + (v * vscale))
Next i
;Read and store faces infos
For i=1 To nbTri
Read.i v1
Read.i v2
Read.i v3
AddMeshFace(v1,v2,v3)
Next i
; Create mesh from stored infos
FinishMesh()
ProcedureReturn newMesh
EndProcedure
DisableExplicit
;- ---- Main loop ----
;-Mesh
; Change parameters 2 to 8 to test the effects on size and texturing
myTetraMesh.i = CreatePlatonicMesh(#tetrahedron,3,3,3)
myCubeMesh.i = CreatePlatonicMesh(#cube,3,3,3)
myOctaMesh.i = CreatePlatonicMesh(#octahedron,3,3,3)
myDodecaMesh.i = CreatePlatonicMesh(#dodecahedron,3,3,3)
myIcosaMesh.i = CreatePlatonicMesh(#icosahedron,3,3,3)
;-Entity
CreateEntity(0,MeshID(myTetraMesh),#PB_Material_None)
CreateEntity(1,MeshID(myCubeMesh),#PB_Material_None)
CreateEntity(2,MeshID(myOctaMesh),#PB_Material_None)
CreateEntity(3,MeshID(myDodecaMesh),#PB_Material_None)
CreateEntity(4,MeshID(myIcosaMesh),#PB_Material_None)
EntityLocate(0,5,5,0)
EntityLocate(1,-5,5,0)
EntityLocate(2,10,-5,0)
EntityLocate(3,0,-5,0)
EntityLocate(4,-10,-5,0)
;-Camera
CreateCamera(0, 0, 0 , 100 , 100)
MoveCamera(0,0,0,-30)
CameraLookAt(0,0,0,0)
viewlabel.s = "Platonic Solids"
;-Light
AmbientColor(RGB(105,105,105))
CreateLight(0,RGB(160,160,255),200,300,0)
CreateLight(1,RGB(255,127,0),-200,-200,200)
pas.f = 0.8
angle.f = 0
Repeat
If fullscreen = 0
While WindowEvent() : Wend
EndIf
; Rotate solids, rotate! Oh, you're so gorgeous... ;)
Angle + Pas
RotateEntity(0, angle,angle/2,-angle)
RotateEntity(1, angle/2,-angle,angle)
RotateEntity(2, -angle,angle,angle/2)
RotateEntity(3, -angle,angle/2,angle)
RotateEntity(4, angle,-angle/2,-angle)
; Manage camera views
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
CameraLocate(0,EntityX(0),EntityY(0),EntityZ(0) - 10)
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))
viewlabel = "Tetrahedron"
EndIf
If KeyboardReleased(#PB_Key_F2)
CameraLocate(0,EntityX(1),EntityY(1),EntityZ(1) - 10)
CameraLookAt(0,EntityX(1),EntityY(1),EntityZ(1))
viewlabel = "Cube"
EndIf
If KeyboardReleased(#PB_Key_F3)
CameraLocate(0,EntityX(2),EntityY(2),EntityZ(2) - 10)
CameraLookAt(0,EntityX(2),EntityY(2),EntityZ(2))
viewlabel = "Octahedron"
EndIf
If KeyboardReleased(#PB_Key_F4)
CameraLocate(0,EntityX(3),EntityY(3),EntityZ(3) - 10)
CameraLookAt(0,EntityX(3),EntityY(3),EntityZ(3))
viewlabel = "Dodecahedron"
EndIf
If KeyboardReleased(#PB_Key_F5)
CameraLocate(0,EntityX(4),EntityY(4),EntityZ(4) - 10)
CameraLookAt(0,EntityX(4),EntityY(4),EntityZ(4))
viewlabel = "Icosahedron"
EndIf
If KeyboardReleased(#PB_Key_F6)
CameraLocate(0,0,0,-30)
CameraLookAt(0,0,0,0)
viewlabel = "Platonic Solids"
EndIf
If KeyboardReleased(#PB_Key_F7)
CameraMode=1-CameraMode
CameraRenderMode(0,CameraMode)
AmbientColor(RGB(105+cameramode*150,105+cameramode*150,105+cameramode*150))
EndIf
EndIf
; show it all
RenderWorld()
; Flip buffers to avoid tearing
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
;- Solids datas
DataSection:
tetrahedron:
; Nb sommets / Nb faces
Data.i 10,4
; Vertices: pos / normals / uv
Data.f 0.817497,0.578350,0
Data.f 0,1,0
Data.f 0.5,0.5
Data.f -0.815497,0.578350,0
Data.f 0,1,0
Data.f 0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0,0.577351,0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0,0.577351,-0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0.816496,-0.577351,0
Data.f 0.5,1.5
Data.f 0.817497,0.578350,0
Data.f 0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,-0.815497
Data.f -0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f -0.815497,0.578350,0
Data.f -0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,0.817497
Data.f -0.816496,-0.577351,0
Data.f 0.5,1.5
; Faces
Data.i 0,1,2
Data.i 1,0,3
Data.i 4,6,5
Data.i 7,9,8
cube:
; Nb sommets / Nb faces
Data.i 24,12
; Vertices: pos / normals / uv
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,1
Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,1
Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,0
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,0
Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,0
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,0
Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,1
Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,1
Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,0
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,0
Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,1
Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,1
Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,0
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.f 0,0
Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.f 0,1
Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.f 1,0
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.f 1,1
Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.f 1,0
; Faces
Data.i 2,1,0
Data.i 0,3,2
Data.i 6,5,4
Data.i 4,7,6
Data.i 10,9,8
Data.i 8,11,10
Data.i 14,13,12
Data.i 12,15,14
Data.i 18,17,16
Data.i 16,19,18
Data.i 22,21,20
Data.i 20,23,22
octahedron:
; Nb sommets / Nb faces
Data.i 18,8
; Vertices: pos / normals / uv
Data.f 0,0.708107,0.708107
Data.f 0,1,0
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0,1,0
Data.f 0,1.5
Data.f 1.001000,0,0
Data.f 1,0,0
Data.f 0.5,1
Data.f 0,-0.706107,0.708107
Data.f 0,0,1
Data.f -0.5,1
Data.f -0.999000,0,0
Data.f -1,0,0
Data.f 0,1.5
Data.f 0,-0.706107,-0.706107
Data.f 0,0,-1
Data.f -0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,0.816496
Data.f 0,0.5
Data.f 0,0.708107,0.708107
Data.f 0.577350,0,0.816496
Data.f 0.5,1
Data.f 0,0.708107,0.708107
Data.f -0.577350,0,0.816496
Data.f 0.5,1
Data.f -0.999000,0,0
Data.f -0.577350,0.816496,0
Data.f -0.5,1
Data.f 0,0.708107,-0.706107
Data.f -0.577350,0,-0.816496
Data.f 0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,-0.816496
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0.577350,0,-0.816496
Data.f 0.5,1
Data.f 0,-0.706107,-0.706107
Data.f 0.577350,-0.816496,0
Data.f 0,1.5
Data.f 0,-0.706107,0.708107
Data.f 0.577350,-0.816496,0
Data.f 0,0.5
Data.f -0.999000,0,0
Data.f -0.577350,-0.816496,0
Data.f -0.5,1
Data.f 0,-0.706107,0.708107
Data.f -0.577350,-0.816496,0
Data.f 0,0.5
Data.f 0,-0.706107,-0.706107
Data.f -0.577350,-0.816496,0
Data.f 0,1.5
; Faces
Data.i 1,0,2
Data.i 6,7,3
Data.i 3,8,4
Data.i 9,0,1
Data.i 4,10,5
Data.i 5,12,11
Data.i 2,14,13
Data.i 15,17,16
dodecahedron:
; Nb sommets / Nb faces
Data.i 72,36
; Vertices: pos / normals / uv
Data.f 0.357822,0.935172,0
Data.f 0,0.955423,0.295242
Data.f 0.190983,1
Data.f -0.355822,0.935172,0
Data.f 0,0.955423,-0.295242
Data.f -0.190983,1
Data.f 0.578350,0.578350,0.578350
Data.f 0.688191,0.587785,0.425325
Data.f 0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0,0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f 0,0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f -0.309017,1.309020
Data.f 0,0.357822,-0.933172
Data.f 0,0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.935172,0,0.357822
Data.f 1,0,0
Data.f 0.190983,1
Data.f 0.935172,0,-0.355822
Data.f 1,0,0
Data.f -0.190983,1
Data.f 0,-0.355822,-0.933172
Data.f 0,0,-1
Data.f -0.190983,1
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f -0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,-0.576350
Data.f -0.425325,-0.688191,-0.587785
Data.f -0.309017,1.309020
Data.f -0.355822,-0.933172,0
Data.f 0,-0.992447,0.122673
Data.f -0.190983,1
Data.f 0,-0.355822,0.935172
Data.f 0,-0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.979432,-0.201774,0
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.992447,0.122673,0
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.357822,0.935172,0
Data.f 0.850651,0.525731,0
Data.f 0,0.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0,0.357822,-0.933172
Data.f 0.525731,0,-0.850651
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.935172,0,-0.355822
Data.f 0.525731,0,-0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0,-0.355822,-0.933172
Data.f 0,-0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,-0.525731
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,0.525731
Data.f 0.190983,1
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,0.578350
Data.f -0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.525731,0,0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.576350,-0.576350,0.578350
Data.f -0.525731,0,0.850651
Data.f -0.309017,1.309020
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.850651,0.525731,0
Data.f 0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.576350,0.578350,-0.576350
Data.f -0.525731,0,-0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,-0.355822,0.935172
Data.f 0.525731,0,0.850651
Data.f -0.190983,1
; Faces
Data.i 0,3,2
Data.i 0,4,3
Data.i 0,1,4
Data.i 1,6,5
Data.i 1,7,6
Data.i 1,0,7
Data.i 20,8,9
Data.i 21,2,8
Data.i 22,23,2
Data.i 24,10,25
Data.i 26,11,10
Data.i 27,28,11
Data.i 29,12,13
Data.i 30,8,12
Data.i 31,9,8
Data.i 32,14,33
Data.i 34,15,14
Data.i 35,36,15
Data.i 15,16,17
Data.i 15,37,16
Data.i 15,39,38
Data.i 40,18,14
Data.i 41,19,18
Data.i 42,43,19
Data.i 44,46,45
Data.i 47,49,48
Data.i 50,52,51
Data.i 19,53,18
Data.i 19,55,54
Data.i 19,57,56
Data.i 58,10,14
Data.i 59,60,10
Data.i 61,63,62
Data.i 64,65,2
Data.i 66,68,67
Data.i 69,71,70
icosahedron:
; Nb sommets / Nb faces
Data.i 42,20
; Vertices: pos / normals / uv
Data.f 0,0.851651,0.526731
Data.f 0,1,0
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0,1,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.356822,0.934172,0
Data.f 0.5,1
Data.f 0.526731,0,0.851651
Data.f 0.810146,0,0.586227
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f 0,0,1
Data.f 0,1.309020
Data.f -0.849651,0.526731,0
Data.f -0.934172,0.356822,0
Data.f 0,0.690983
Data.f -0.524731,0,-0.849651
Data.f -0.810146,0,-0.586227
Data.f -0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0,0,-1
Data.f 0,0.690983
Data.f 0.851651,-0.524731,0
Data.f 0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0,-0.356822,-0.934172
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f 0,-0.707107,0.707107
Data.f 0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,0.577350
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f 0.526731,0,0.851651
Data.f 0,0.356822,0.934172
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0,0.356822,0.934172
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.577350,0.577350,0.577350
Data.f 0.5,1
Data.f 0,0.851651,0.526731
Data.f -0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f -0.849651,0.526731,0
Data.f -0.356822,0.934172,0
Data.f -0.5,1
Data.f 0,0.851651,-0.524731
Data.f -0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f -0.524731,0,-0.849651
Data.f 0,0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,0.851651,-0.524731
Data.f 0,0.356822,-0.934172
Data.f 0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0.577350,0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,-0.577350
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,0.356822
Data.f 0,0.690983
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,-0.356822
Data.f 0,0.690983
Data.f 0.526731,0,-0.849651
Data.f 0.934172,0,-0.356822
Data.f -0.5,1
Data.f -0.524731,0,-0.849651
Data.f 0,-0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f 0.526731,0,-0.849651
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,-0.524731,0
Data.f 0.356822,-0.934172,0
Data.f 0.5,1
Data.f 0,-0.849651,-0.524731
Data.f 0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.356822,-0.934172,0
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f -0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0,-0.356822,0.934172
Data.f -0.5,1
Data.f 0.526731,0,0.851651
Data.f 0,-0.356822,0.934172
Data.f 0,0.690983
Data.f -0.524731,0,0.851651
Data.f -0.577350,-0.577350,0.577350
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.934172,0,0.356822
Data.f 0.5,1
; Faces
Data.i 1,0,2
Data.i 12,13,3
Data.i 14,15,4
Data.i 16,17,5
Data.i 18,0,1
Data.i 5,19,6
Data.i 20,21,7
Data.i 22,24,23
Data.i 25,3,8
Data.i 26,8,27
Data.i 28,7,9
Data.i 29,30,8
Data.i 8,3,10
Data.i 31,33,32
Data.i 6,34,11
Data.i 35,37,36
Data.i 38,39,4
Data.i 10,40,11
Data.i 6,11,5
Data.i 5,11,41
EndDataSection
Last edited by Kelebrindae on Thu Jun 07, 2012 9:42 am, edited 1 time in total.
-
Kelebrindae
- Enthusiast

- Posts: 151
- Joined: Tue Apr 01, 2008 3:23 pm
Re: Ogre3D basic obecjst movement examples?
And another, which demonstrates how to move an entity. It includes quaternions, to avoid the gimbal lock:
(Again, it's a very old code, so it's far from perfect...)
[EDIT] updated for PB4.61
(Again, it's a very old code, so it's far from perfect...)
[EDIT] updated for PB4.61
Code: Select all
; Moving_an_entity_quaternion
; Author: Comtois, modified by Kelebrindae to add pitch control without gimbal lock
; Date: 3 fevrier 2008 (last updated 06/06/2012)
; PB version: v4.61
; OS: Windows XP
; Demo: Yes
; Arrow keys => change orientation
; S/X => move forward/backward
; F1 to F5 => change camera view
; Unofficial rotation flag values ;)
#PB_Engine_Space_Local=1
#PB_Engine_Space_Parent=2
#PB_Engine_Space_World=4
#PB_Engine_Absolute_Rotation=8
#PB_Engine_Relative_Rotation=16
#PB_Engine_Quaternion_Rotation=32
#PB_Engine_Euler_Rotation=64
#PB_Engine_Absolute_Rotation_quat = #PB_Engine_Space_world | #PB_Engine_quaternion_Rotation | #PB_Engine_Absolute_Rotation
;- Initialisation
If InitEngine3D() = 0
MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 )
End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 )
End
EndIf
Resultat = MessageRequester("Move entity","Full Screen ?",#PB_MessageRequester_YesNo)
If Resultat = 6
FullScreen=1
ExamineDesktops()
OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0), "Move entity")
Else
FullScreen=0
OpenWindow(0,0, 0, 1024 , 768 ,"Move entity",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0, 1024 , 768,0,0,0)
EndIf
EnableExplicit
;- Structures and globals
#DEG2RAD = 0.0174533
#Mesh = 0
#Texture = 0
#TextureSol = 1
#Material = 0
#MaterialGround = 1
#Entity = 0
#EntityGround = 1
#Camera = 0
Enumeration
#TopView
#RearView
#SideView
#FrontView
#FixedView
EndEnumeration
Structure quaternion
x.f
y.f
z.f
w.f
EndStructure
Structure vector3
x.f
y.f
z.f
EndStructure
Global norm.f
Global cQuat.quaternion
Global pResultVector.vector3
Global azimuth.f,pitch.f,roll.f
Global speed.f = 1
Define.l Options, ModeCamera, i
ModeCamera = #RearView
;- --- Macros ---
Macro NEW_X(x, Angle, Distance)
((x) + Cos((Angle) * #DEG2RAD) * (Distance))
EndMacro
Macro NEW_Z(z, Angle, Distance)
((z) - Sin((Angle) * #DEG2RAD) * (Distance))
EndMacro
;- --- Procedures ---
;- Camera management
Procedure.f CurveValue(current.f, target.f, P.f)
Protected Delta.f
Delta = target - current
If P > 1000.0
P = 1000.0
EndIf
ProcedureReturn (current + ( Delta * P / 1000.0))
EndProcedure
Procedure.f wrapValueF(angle.f)
If angle < 0
ProcedureReturn angle+360
Else
If angle >= 360
ProcedureReturn angle-360
EndIf
EndIf
ProcedureReturn angle
EndProcedure
Procedure ManageCamera(Mode.l)
Protected Px.f, Py.f, Pz.f, Pv.f = 25
Static AngleCamera.f
Select Mode
Case #TopView
AngleCamera = CurveValue(AngleCamera, azimuth + 270, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 40), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 140, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 40), Pv)
Case #RearView
AngleCamera = CurveValue(AngleCamera, azimuth + 270, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 80), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 40, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 80), Pv)
Case #SideView
AngleCamera = CurveValue(AngleCamera, azimuth + 180, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 80), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 40, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 80), Pv)
Case #FrontView
AngleCamera = CurveValue(AngleCamera, azimuth + 90, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 80), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 40, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 80), Pv)
EndSelect
If Mode <> #FixedView
CameraLocate(#Camera, Px, Py, Pz)
EndIf
CameraLookAt(#Camera, EntityX(#Entity), EntityY(#Entity), EntityZ(#Entity))
EndProcedure
;- Quaternions, to avoid gimbal lock
Procedure EulerAnglesToQuat(x.f,y.f,z.f)
Protected roll.f,pitch.f,yaw.f
Protected cyaw.f, cpitch.f, croll.f, syaw.f, spitch.f, sroll.f
Protected cyawcpitch.f, syawspitch.f, cyawspitch.f, syawcpitch.f
roll = x
pitch= y
yaw = z
cyaw = Cos(0.5 * yaw)
cpitch = Cos(0.5 * pitch)
croll = Cos(0.5 * roll)
syaw = Sin(0.5 * yaw)
spitch = Sin(0.5 * pitch)
sroll = Sin(0.5 * roll)
cyawcpitch = cyaw*cpitch
syawspitch = syaw*spitch
cyawspitch = cyaw*spitch
syawcpitch = syaw*cpitch
norm = (cyawcpitch * croll + syawspitch * sroll)
cQuat\x = (cyawcpitch * sroll - syawspitch * croll)
cQuat\y = (cyawspitch * croll + syawcpitch * sroll)
cQuat\z = (syawcpitch * croll - cyawspitch * sroll)
cQuat\w = norm
EndProcedure
Procedure QuaternionTransform(x.f,y.f,z.f)
pResultVector\x = cQuat\w*cQuat\w*x + 2*cQuat\y*cQuat\w*z - 2*cQuat\z*cQuat\w*y + cQuat\x*cQuat\x*x + 2*cQuat\y*cQuat\x*y + 2*cQuat\z*cQuat\x*z - cQuat\z*cQuat\z*x - cQuat\y*cQuat\y*x
pResultVector\y = 2*cQuat\x*cQuat\y*x + cQuat\y*cQuat\y*y + 2*cQuat\z*cQuat\y*z + 2*cQuat\w*cQuat\z*x - cQuat\z*cQuat\z*y + cQuat\w*cQuat\w*y - 2*cQuat\x*cQuat\w*z - cQuat\x*cQuat\x*y;
pResultVector\z = 2*cQuat\x*cQuat\z*x + 2*cQuat\y*cQuat\z*y + cQuat\z*cQuat\z*z - 2*cQuat\w*cQuat\y*x - cQuat\y*cQuat\y*z + 2*cQuat\w*cQuat\x*y - cQuat\x*cQuat\x*z + cQuat\w*cQuat\w*z;
EndProcedure
Procedure myCreateCube(numMesh.i)
Protected x.f,y.f,z.f ; vertex position
Protected nx.f,ny.f,nz.f ; vertex normals
Protected color.l
Protected u.f,v.f ; vertex UV coords (texture mapping)
Protected newmesh.i ; Procedure Result
Protected i.i,v1.i,v2.i,v3.i
CreateMesh(numMesh)
For i = 1 To 24
Read.f x
Read.f y
Read.f z
Read.f nx
Read.f ny
Read.f nz
Read.l color
Read.f u
Read.f v
AddMeshVertex(x,y,z)
MeshVertexNormal(nx,ny,nz)
MeshVertexColor(color)
MeshVertexTextureCoordinate(u,v)
Next i
;Read and store faces infos
For i=1 To 12
Read.i v1
Read.i v2
Read.i v3
AddMeshFace(v1,v2,v3)
Next i
; Create mesh from stored infos
FinishMesh()
EndProcedure
;- --- Main code ---
;-Mesh
MyCreateCube(#Mesh)
;-Textures
;Cube texture (yellow = front)
CreateTexture(#Texture,128,128)
StartDrawing(TextureOutput(#Texture))
Box(0, 0, TextureWidth(0)/3, TextureHeight(0)/2, $FF00FF)
Box(TextureWidth(0)/3, 0,TextureWidth(0)/3, TextureHeight(0)/2, $FF0000)
Box(2*TextureWidth(0)/3, 0,TextureWidth(0)/3, TextureHeight(0)/2, $00FF00)
Box(0, TextureHeight(0)/2, TextureWidth(0)/3, TextureHeight(0)/2, $00FFFF)
Box(TextureWidth(0)/3, TextureWidth(0)/2,TextureWidth(0)/3, TextureHeight(0)/2, $FFFF00)
Box(2*TextureWidth(0)/3, TextureHeight(0)/2,TextureWidth(0)/3, TextureHeight(0)/2, $0000FF)
; smiley face ;)
DrawingMode(#PB_2DDrawing_Outlined)
Circle(TextureWidth(0)/6, TextureHeight(0)/2 + TextureWidth(0)/4,TextureWidth(0)/8,$000000)
DrawingMode(#PB_2DDrawing_Default)
Box(0, TextureHeight(0)/2,TextureWidth(0)/4, TextureHeight(0)/2, $00FFFF)
Circle(TextureWidth(0)/8,TextureHeight(0)/2 + 2*TextureWidth(0)/16,TextureWidth(0)/16,$000000)
Circle(TextureWidth(0)/8,TextureHeight(0)/2 + 6*TextureWidth(0)/16,TextureWidth(0)/16,$000000)
; black borders
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, TextureWidth(0)/3, TextureHeight(0)/2, 0)
Box(TextureWidth(0)/3, 0,TextureWidth(0)/3, TextureHeight(0)/2, 0)
Box(2*TextureWidth(0)/3, 0,TextureWidth(0)/3, TextureHeight(0)/2, 0)
Box(0, TextureHeight(0)/2, TextureWidth(0)/3, TextureHeight(0)/2, 0)
Box(TextureWidth(0)/3, TextureWidth(0)/2,TextureWidth(0)/3, TextureHeight(0)/2, 0)
Box(2*TextureWidth(0)/3, TextureHeight(0)/2,TextureWidth(0)/3, TextureHeight(0)/2, 0)
StopDrawing()
;Ground texture
CreateTexture(#TextureSol,256,256)
StartDrawing(TextureOutput(#TextureSol))
Box(0, 0, TextureWidth(0), TextureHeight(0), $007700)
For i = 0 To 255 Step 16
Line(i, 0, 1, TextureHeight(0), $00FF00)
Line(0, i, TextureWidth(0), 1, $00FF00)
Next i
StopDrawing()
;-Material
CreateMaterial(#Material, TextureID(#Texture))
CreateMaterial(#MaterialGround, TextureID(#TextureSol))
;-Entities
CreateEntity(#Entity, MeshID(#Mesh), MaterialID(#Material))
EntityLocate(#Entity, 500, 15, 500)
CreateEntity(#EntityGround, MeshID(#Mesh), MaterialID(#MaterialGround))
ScaleEntity(#EntityGround, 100, 0.2, 100)
EntityLocate(#EntityGround, 500, 9, 500)
EntityRenderMode(#EntityGround,#PB_Entity_Solid)
;-Camera
CreateCamera(#Camera, 0, 0, 100, 100)
;-Light
AmbientColor($BBBBBB)
CreateLight(0,$FFFFFF, 0,500,0)
;-Shadows
WorldShadows(#PB_Shadow_Modulative)
RotateEntity(#Entity, roll, azimuth, pitch)
Repeat
If ExamineKeyboard()
;Change camera view
If KeyboardReleased(#PB_Key_F1)
ModeCamera = #TopView
ElseIf KeyboardReleased(#PB_Key_F2)
ModeCamera = #RearView
ElseIf KeyboardReleased(#PB_Key_F3)
ModeCamera = #SideView
ElseIf KeyboardReleased(#PB_Key_F4)
ModeCamera = #FrontView
ElseIf KeyboardReleased(#PB_Key_F5)
ModeCamera = #FixedView
EndIf
; Azimuth
If KeyboardPushed(#PB_Key_Left)
azimuth = wrapValueF( azimuth + 1 )
RotateEntity(#Entity, pitch, azimuth, roll, #PB_Engine_Absolute_Rotation_quat)
ElseIf KeyboardPushed(#PB_Key_Right)
azimuth = wrapValueF( azimuth - 1 )
RotateEntity(#Entity, pitch, azimuth, roll, #PB_Engine_Absolute_Rotation_quat)
EndIf
; Pitch
If KeyboardPushed(#PB_Key_Down)
pitch = wrapValueF( pitch + 1 )
RotateEntity(#Entity, pitch, azimuth, roll, #PB_Engine_Absolute_Rotation_quat)
ElseIf KeyboardPushed(#PB_Key_Up)
pitch = wrapValueF( pitch - 1 )
RotateEntity(#Entity, pitch, azimuth, roll, #PB_Engine_Absolute_Rotation_quat)
EndIf
; Speed
If KeyboardPushed(#PB_Key_S)
EulerAnglesToQuat(pitch * #DEG2RAD,azimuth * #DEG2RAD,roll * #DEG2RAD )
QuaternionTransform(0,0,-speed)
MoveEntity(#Entity, pResultVector\x,pResultVector\y,pResultVector\z)
ElseIf KeyboardPushed(#PB_Key_X)
EulerAnglesToQuat(pitch * #DEG2RAD,azimuth * #DEG2RAD,roll * #DEG2RAD )
QuaternionTransform(0,0,speed)
MoveEntity(#Entity, pResultVector\x,pResultVector\y,pResultVector\z)
EndIf
EndIf
ManageCamera(ModeCamera)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
;- Meshes datas
DataSection
Vertex:
;Top 0 à 3
Data.f -5,5,-5
Data.f 0,1,0
Data.l 0
Data.f 0,0
Data.f 5,5,-5
Data.f 0,1,0
Data.l 0
Data.f 0,0.5
Data.f 5,5,5
Data.f 0,1,0
Data.l 0
Data.f 0.333,0.5
Data.f -5,5,5
Data.f 0,1,0
Data.l 0
Data.f 0.333,0
;Bottom 4 à 7
Data.f -5,-5,5
Data.f 0,-1,0
Data.l 0
Data.f 0.333,0
Data.f 5,-5,5
Data.f 0,-1,0
Data.l 0
Data.f 0.333,0.5
Data.f 5,-5,-5
Data.f 0,-1,0
Data.l 0
Data.f 0.666,0.5
Data.f -5,-5,-5
Data.f 0,-1,0
Data.l 0
Data.f 0.666,0
;Front 8 à 11
Data.f -5,5,5
Data.f 0,0,1
Data.l 0
Data.f 0.666,0
Data.f 5,5,5
Data.f 0,0,1
Data.l 0
Data.f 0.666,0.5
Data.f 5,-5,5
Data.f 0,0,1
Data.l 0
Data.f 1,0.5
Data.f -5,-5,5
Data.f 0,0,1
Data.l 0
Data.f 1,0
;Back 12 à 15
Data.f 5,5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0,0.5
Data.f -5,5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0,1
Data.f -5,-5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0.333,1
Data.f 5,-5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0.333,0.5
;Left 16 à 19
Data.f -5,5,-5
Data.f -1,0,0
Data.l 0
Data.f 0.333,0.5
Data.f -5,5,5
Data.f -1,0,0
Data.l 0
Data.f 0.333,1
Data.f -5,-5,5
Data.f -1,0,0
Data.l 0
Data.f 0.666,1
Data.f -5,-5,-5
Data.f -1,0,0
Data.l 0
Data.f 0.666,0.5
;Right 20 à 23
Data.f 5,5,5
Data.f 1,0,0
Data.l 0
Data.f 0.666,0.5
Data.f 5,5,-5
Data.f 1,0,0
Data.l 0
Data.f 0.666,1
Data.f 5,-5,-5
Data.f 1,0,0
Data.l 0
Data.f 1,1
Data.f 5,-5,5
Data.f 1,0,0
Data.l 0
Data.f 1,0.5
Triangles:
;Top
Data.i 0,2,1
Data.i 2,0,3
;Bottom
Data.i 6,5,4
Data.i 4,7,6
;Right
Data.i 22,21,20
Data.i 20,23,22
;Back
Data.i 14,13,12
Data.i 12,15,14
;Left
Data.i 18,17,16
Data.i 16,19,18
;Front
Data.i 10,9,8
Data.i 8,11,10
EndDataSection
Last edited by Kelebrindae on Thu Jun 07, 2012 10:45 am, edited 1 time in total.
Re: Ogre3D basic obecjst movement examples?
Kelebrindae,
Thank you very much, those are very nice 3D examples!!
Your examples showed the 3D capabilities of PureBasic and it is quite impressive.
One question about using RotateEntity"
In your example, it looks like the rotation is about the center of the object, is it possible to specify an axis of rotation? For example, rotate the box about an axis that pass through two opposite corner of the box.
Very nice examples, I will have to study your codes more carefully.
Thank you.
Thank you very much, those are very nice 3D examples!!
Your examples showed the 3D capabilities of PureBasic and it is quite impressive.
One question about using RotateEntity"
In your example, it looks like the rotation is about the center of the object, is it possible to specify an axis of rotation? For example, rotate the box about an axis that pass through two opposite corner of the box.
Very nice examples, I will have to study your codes more carefully.
Thank you.
Re: Ogre3D basic obecjst movement examples?
Added CurveAngle and WrapValue
Code: Select all
; Moving_an_entity_quaternion
; Author: Kelebrindae, based on a demo from Comtois
; Date: 3 fevrier 2008 (updated later for 4.40)
; PB version: v4.00
; OS: Windows XP
; Demo: Yes
; Arrow keys => change orientation
; S/X => move forward/backward
; F1 to F5 => change camera view
;- Initialisation
If InitEngine3D() = 0
MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 )
End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 )
End
EndIf
Resultat = MessageRequester("Move entity","Full Screen ?",#PB_MessageRequester_YesNo)
If Resultat = 6
FullScreen=1
ExamineDesktops()
OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0), "Move entity")
Else
FullScreen=0
OpenWindow(0,0, 0, 1024 , 768 ,"Move entity",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0, 1024 , 768,0,0,0)
EndIf
EnableExplicit
;- Structures and globals
#DEG2RAD = 0.0174533
#Mesh = 0
#Texture = 0
#TextureSol = 1
#Material = 0
#MaterialGround = 1
#Entity = 0
#EntityGround = 1
#Camera = 0
Enumeration
#TopView
#RearView
#SideView
#FrontView
#FixedView
EndEnumeration
Structure quaternion
x.f
y.f
z.f
w.f
EndStructure
Structure vector3
x.f
y.f
z.f
EndStructure
Global norm.f
Global cQuat.quaternion
Global pResultVector.vector3
Global azimuth.f,pitch.f,roll.f
Global speed.f = 1
Define.l Options, ModeCamera, i
ModeCamera = #RearView
;- --- Macros ---
Macro NEW_X(x, Angle, Distance)
((x) + Cos((Angle) * #DEG2RAD) * (Distance))
EndMacro
Macro NEW_Z(z, Angle, Distance)
((z) - Sin((Angle) * #DEG2RAD) * (Distance))
EndMacro
;- --- Procedures ---
;- Camera management
Procedure.f CurveValue(current.f, target.f, P.f)
Protected Delta.f
Delta = target - current
If P > 1000.0
P = 1000.0
EndIf
ProcedureReturn (current + ( Delta * P / 1000.0))
EndProcedure
Procedure.f wrapValueF(angle.f)
If angle < 0
ProcedureReturn angle+360
Else
If angle >= 360
ProcedureReturn angle-360
EndIf
EndIf
ProcedureReturn angle
EndProcedure
Procedure.f WrapValue(angle.f); <- wraps a value into [0,360) fringe
;Psychophanta : http://purebasic.fr/english/viewtopic.php?t=18635
!fild dword[@f] ; <- now i have 360 into st0
!fld dword[p.v_angle]
!fprem
!fadd st1,st0
!fldz
!fcomip st1
!fcmovnbe st0,st1
!fstp st1
ProcedureReturn
!@@:dd 360
EndProcedure
Procedure.f EcartAngle( Angle1.f , Angle2.f )
Define Delta.f
Delta=Angle2-Angle1
If Delta>180
ProcedureReturn Delta-360
ElseIf Delta<=-180
ProcedureReturn Delta+360
Else
ProcedureReturn Delta
EndIf
EndProcedure
Procedure.f CurveAngle( actuelle.f , Cible.f , P.f )
;Calcule un angle progressif allant de la valeur actuelle à la valeur cible
Define Delta.f, Valeur.f
Delta = EcartAngle( actuelle , Cible )
If P > 1000 : P = 1000 : EndIf
Valeur = actuelle + ( Delta * P / 1000 )
ProcedureReturn WrapValue( Valeur )
EndProcedure
Procedure ManageCamera(Mode.l)
Protected Px.f, Py.f, Pz.f, Pv.f = 25
Static AngleCamera.f
Select Mode
Case #TopView
AngleCamera = CurveAngle(AngleCamera, azimuth + 270, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 40), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 140, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 40), Pv)
Case #RearView
AngleCamera = CurveAngle(AngleCamera, azimuth + 270, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 80), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 40, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 80), Pv)
Case #SideView
AngleCamera = CurveAngle(AngleCamera, azimuth + 180, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 80), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 40, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 80), Pv)
Case #FrontView
AngleCamera = CurveAngle(AngleCamera, azimuth + 90, Pv)
Px = CurveValue(CameraX(#Camera), NEW_X(EntityX(#Entity), AngleCamera, 80), Pv)
Py = CurveValue(CameraY(#Camera), EntityY(#Entity) + 40, Pv)
Pz = CurveValue(CameraZ(#Camera), NEW_Z(EntityZ(#Entity), AngleCamera, 80), Pv)
EndSelect
If Mode <> #FixedView
CameraLocate(#Camera, Px, Py, Pz)
EndIf
CameraLookAt(#Camera, EntityX(#Entity), EntityY(#Entity), EntityZ(#Entity))
EndProcedure
;- Quaternions, to avoid gimbal lock
Procedure EulerAnglesToQuat(x.f,y.f,z.f)
Protected roll.f,pitch.f,yaw.f
Protected cyaw.f, cpitch.f, croll.f, syaw.f, spitch.f, sroll.f
Protected cyawcpitch.f, syawspitch.f, cyawspitch.f, syawcpitch.f
roll = x
pitch= y
yaw = z
cyaw = Cos(0.5 * yaw)
cpitch = Cos(0.5 * pitch)
croll = Cos(0.5 * roll)
syaw = Sin(0.5 * yaw)
spitch = Sin(0.5 * pitch)
sroll = Sin(0.5 * roll)
cyawcpitch = cyaw*cpitch
syawspitch = syaw*spitch
cyawspitch = cyaw*spitch
syawcpitch = syaw*cpitch
norm = (cyawcpitch * croll + syawspitch * sroll)
cQuat\x = (cyawcpitch * sroll - syawspitch * croll)
cQuat\y = (cyawspitch * croll + syawcpitch * sroll)
cQuat\z = (syawcpitch * croll - cyawspitch * sroll)
cQuat\w = norm
EndProcedure
Procedure QuaternionTransform(x.f,y.f,z.f)
pResultVector\x = cQuat\w*cQuat\w*x + 2*cQuat\y*cQuat\w*z - 2*cQuat\z*cQuat\w*y + cQuat\x*cQuat\x*x + 2*cQuat\y*cQuat\x*y + 2*cQuat\z*cQuat\x*z - cQuat\z*cQuat\z*x - cQuat\y*cQuat\y*x
pResultVector\y = 2*cQuat\x*cQuat\y*x + cQuat\y*cQuat\y*y + 2*cQuat\z*cQuat\y*z + 2*cQuat\w*cQuat\z*x - cQuat\z*cQuat\z*y + cQuat\w*cQuat\w*y - 2*cQuat\x*cQuat\w*z - cQuat\x*cQuat\x*y;
pResultVector\z = 2*cQuat\x*cQuat\z*x + 2*cQuat\y*cQuat\z*y + cQuat\z*cQuat\z*z - 2*cQuat\w*cQuat\y*x - cQuat\y*cQuat\y*z + 2*cQuat\w*cQuat\x*y - cQuat\x*cQuat\x*z + cQuat\w*cQuat\w*z;
EndProcedure
;- --- Main code ---
;-Mesh
CreateMesh(#Mesh, 100)
Options = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate
SetMeshData(#Mesh, Options , ?Vertex, 24)
SetMeshData(#Mesh, #PB_Mesh_Face, ?Triangles, 12)
;-Textures
Add3DArchive(".",#PB_3DArchive_FileSystem)
;Cube texture (yellow = front)
CreateImage(0,128,128)
StartDrawing(ImageOutput(0))
Box(0, 0, ImageWidth(0)/3, ImageHeight(0)/2, $FF00FF)
Box(ImageWidth(0)/3, 0,ImageWidth(0)/3, ImageHeight(0)/2, $FF0000)
Box(2*ImageWidth(0)/3, 0,ImageWidth(0)/3, ImageHeight(0)/2, $00FF00)
Box(0, ImageHeight(0)/2, ImageWidth(0)/3, ImageHeight(0)/2, $0000FF)
Box(ImageWidth(0)/3, ImageWidth(0)/2,ImageWidth(0)/3, ImageHeight(0)/2, $FFFF00)
Box(2*ImageWidth(0)/3, ImageHeight(0)/2,ImageWidth(0)/3, ImageHeight(0)/2, $00FFFF)
; smiley face ;)
DrawingMode(#PB_2DDrawing_Outlined)
Circle(2*ImageWidth(0)/3 + ImageWidth(0)/6, ImageHeight(0)/2 + ImageWidth(0)/4,ImageWidth(0)/8,$000000)
DrawingMode(#PB_2DDrawing_Default)
Box(2*ImageWidth(0)/3, ImageHeight(0)/2,ImageWidth(0)/4, ImageHeight(0)/2, $00FFFF)
Circle(2*ImageWidth(0)/3 + ImageWidth(0)/8,ImageHeight(0)/2 + 2*ImageWidth(0)/16,ImageWidth(0)/16,$000000)
Circle(2*ImageWidth(0)/3 + ImageWidth(0)/8,ImageHeight(0)/2 + 6*ImageWidth(0)/16,ImageWidth(0)/16,$000000)
; black borders
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, ImageWidth(0)/3, ImageHeight(0)/2, 0)
Box(ImageWidth(0)/3, 0,ImageWidth(0)/3, ImageHeight(0)/2, 0)
Box(2*ImageWidth(0)/3, 0,ImageWidth(0)/3, ImageHeight(0)/2, 0)
Box(0, ImageHeight(0)/2, ImageWidth(0)/3, ImageHeight(0)/2, 0)
Box(ImageWidth(0)/3, ImageWidth(0)/2,ImageWidth(0)/3, ImageHeight(0)/2, 0)
Box(2*ImageWidth(0)/3, ImageHeight(0)/2,ImageWidth(0)/3, ImageHeight(0)/2, 0)
StopDrawing()
SaveImage(0,"temp.bmp")
FreeImage(0)
LoadTexture(#Texture,"temp.bmp")
DeleteFile("temp.bmp")
;Ground texture
CreateImage(0,256,256)
StartDrawing(ImageOutput(0))
Box(0, 0, ImageWidth(0), ImageHeight(0), $007700)
For i = 0 To 255 Step 16
Line(i, 0, 1, ImageHeight(0), $00FF00)
Line(0, i, ImageWidth(0), 1, $00FF00)
Next i
StopDrawing()
SaveImage(0,"temp2.bmp")
FreeImage(0)
LoadTexture(#TextureSol,"temp2.bmp")
DeleteFile("temp2.bmp")
;-Material
CreateMaterial(#Material, TextureID(#Texture))
CreateMaterial(#MaterialGround, TextureID(#TextureSol))
;-Entities
CreateEntity(#Entity, MeshID(#Mesh), MaterialID(#Material))
EntityLocate(#Entity, 500, 15, 500)
CreateEntity(#EntityGround, MeshID(#Mesh), MaterialID(#MaterialGround))
ScaleEntity(#EntityGround, 100, 0.2, 100)
EntityLocate(#EntityGround, 500, 9, 500)
EntityRenderMode(#EntityGround,#PB_Entity_Solid)
;-Camera
CreateCamera(#Camera, 0, 0, 100, 100)
;-Light
AmbientColor($BBBBBB)
CreateLight(0,$FFFFFF, 0,500,0)
;-Shadows
WorldShadows(#PB_Shadow_Modulative)
RotateEntity(#Entity, roll, azimuth+90, pitch)
Repeat
If ExamineKeyboard()
;Change camera view
If KeyboardReleased(#PB_Key_F1)
ModeCamera = #TopView
ElseIf KeyboardReleased(#PB_Key_F2)
ModeCamera = #RearView
ElseIf KeyboardReleased(#PB_Key_F3)
ModeCamera = #SideView
ElseIf KeyboardReleased(#PB_Key_F4)
ModeCamera = #FrontView
ElseIf KeyboardReleased(#PB_Key_F5)
ModeCamera = #FixedView
EndIf
; Azimuth
If KeyboardPushed(#PB_Key_Left)
azimuth = wrapValueF( azimuth + 1 )
RotateEntity(#Entity, roll, azimuth+90, pitch)
ElseIf KeyboardPushed(#PB_Key_Right)
azimuth = wrapValueF( azimuth - 1 )
RotateEntity(#Entity, roll, azimuth+90, pitch)
EndIf
; Pitch
If KeyboardPushed(#PB_Key_Down)
pitch = wrapValueF( pitch + 1 )
RotateEntity(#Entity, roll, azimuth+90, pitch)
ElseIf KeyboardPushed(#PB_Key_Up)
pitch = wrapValueF( pitch - 1 )
RotateEntity(#Entity, roll, azimuth+90, pitch)
EndIf
; Speed
If KeyboardPushed(#PB_Key_S)
EulerAnglesToQuat(pitch * #DEG2RAD,azimuth * #DEG2RAD,roll * #DEG2RAD )
QuaternionTransform(0,0,-speed)
MoveEntity(#Entity, pResultVector\x,pResultVector\y,pResultVector\z)
ElseIf KeyboardPushed(#PB_Key_X)
EulerAnglesToQuat(pitch * #DEG2RAD,azimuth * #DEG2RAD,roll * #DEG2RAD )
QuaternionTransform(0,0,speed)
MoveEntity(#Entity, pResultVector\x,pResultVector\y,pResultVector\z)
EndIf
EndIf
ManageCamera(ModeCamera)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
;- Meshes datas
DataSection
Vertex:
;Top 0 à 3
Data.f -5,5,-5
Data.f 0,1,0
Data.l 0
Data.f 0,0
Data.f 5,5,-5
Data.f 0,1,0
Data.l 0
Data.f 0,0.5
Data.f 5,5,5
Data.f 0,1,0
Data.l 0
Data.f 0.333,0.5
Data.f -5,5,5
Data.f 0,1,0
Data.l 0
Data.f 0.333,0
;Bottom 4 à 7
Data.f -5,-5,5
Data.f 0,-1,0
Data.l 0
Data.f 0.333,0
Data.f 5,-5,5
Data.f 0,-1,0
Data.l 0
Data.f 0.333,0.5
Data.f 5,-5,-5
Data.f 0,-1,0
Data.l 0
Data.f 0.666,0.5
Data.f -5,-5,-5
Data.f 0,-1,0
Data.l 0
Data.f 0.666,0
;Front 8 à 11
Data.f -5,5,5
Data.f 0,0,1
Data.l 0
Data.f 0.666,0
Data.f 5,5,5
Data.f 0,0,1
Data.l 0
Data.f 0.666,0.5
Data.f 5,-5,5
Data.f 0,0,1
Data.l 0
Data.f 1,0.5
Data.f -5,-5,5
Data.f 0,0,1
Data.l 0
Data.f 1,0
;Back 12 à 15
Data.f 5,5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0,0.5
Data.f -5,5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0,1
Data.f -5,-5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0.333,1
Data.f 5,-5,-5
Data.f 0,0,-1
Data.l 0
Data.f 0.333,0.5
;Left 16 à 19
Data.f -5,5,-5
Data.f -1,0,0
Data.l 0
Data.f 0.333,0.5
Data.f -5,5,5
Data.f -1,0,0
Data.l 0
Data.f 0.333,1
Data.f -5,-5,5
Data.f -1,0,0
Data.l 0
Data.f 0.666,1
Data.f -5,-5,-5
Data.f -1,0,0
Data.l 0
Data.f 0.666,0.5
;Right 20 à 23
Data.f 5,5,5
Data.f 1,0,0
Data.l 0
Data.f 0.666,0.5
Data.f 5,5,-5
Data.f 1,0,0
Data.l 0
Data.f 0.666,1
Data.f 5,-5,-5
Data.f 1,0,0
Data.l 0
Data.f 1,1
Data.f 5,-5,5
Data.f 1,0,0
Data.l 0
Data.f 1,0.5
Triangles:
;Top
Data.w 0,2,1
Data.w 2,0,3
;Bottom
Data.w 6,5,4
Data.w 4,7,6
;Right
Data.w 22,21,20
Data.w 20,23,22
;Back
Data.w 14,13,12
Data.w 12,15,14
;Left
Data.w 18,17,16
Data.w 16,19,18
;Front
Data.w 10,9,8
Data.w 8,11,10
EndDataSection
;}Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Re: Ogre3D basic obecjst movement examples?
Comtois,
Thank you for adding CurveAngle and WrapValue.
I have more studying to do.

Thank you for adding CurveAngle and WrapValue.
I have more studying to do.
Re: Ogre3D basic obecjst movement examples?
Thank you for the help.
I will study the codes further.

I will study the codes further.
Re: Ogre3D basic obecjst movement examples?
Kelebrindae has updated his excellent 3D example to PB 4.51.
Code: Select all
; Author: Kelebrindae (modification of the "cylinder 3D" demo, from Comtois)
; Date: march,13, 2006
; PB version: v4.51
; OS: Windows XP
; Demo: Yes
;- Initialisation
Resultat = MessageRequester("Platonic Solids","Full Screen ?",#PB_MessageRequester_YesNo)
If Resultat = 6
FullScreen=1
Else
FullScreen=0
EndIf
If InitEngine3D() = 0
MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 )
End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 )
End
EndIf
If Fullscreen
OpenScreen(800,600,32,"Platonic Solids")
Else
OpenWindow(0,0, 0, 800 , 600 ,"Platonic Solids",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0, 800 , 600,0,0,0)
EndIf
;- Data structures and definitions
Global CameraMode.i
Structure Vertex
px.f
py.f
pz.f
nx.f
ny.f
nz.f
Couleur.i
U.f
V.f
EndStructure
Structure Triangle
f1.w
f2.w
f3.w
EndStructure
Enumeration
#tetrahedron
#cube
#octahedron
#dodecahedron
#icosahedron
EndEnumeration
EnableExplicit
;- ---- Procedures ----
;************************************************************************************
; Name: CreatePlatonicMesh
; Purpose: Create a platonic solid mesh, scaled and UV mapped dynamically
; Parameters:
; - solide: #tetrahedron,#cube,#octahedron,#dodecahedron, or #icosahedron
; - X size
; - Y size
; - Z size
; - origin of mapping coord U
; - origin of mapping coord V
; - Vertices color
; Return value: mesh number, or -1 if an error occurs
;************************************************************************************
Procedure.i CreatePlatonicMesh(solid.i,sizeX.f = 1,sizeY.f = 1,sizeZ.f = 1,Uorigin.f = 0,Vorigin.f = 0,Uscale.f = 1,Vscale.f = 1,color.i = $FFFFFF)
Protected nbVert.i , nbTri.i ; Number of vertices and faces
Protected x.f,y.f,z.f ; vertex position
Protected nx.f,ny.f,nz.f ; vertex normals
Protected u.f,v.f ; vertex UV coords (texture mapping)
Protected *PtrV.Vertex,*vertexBuffer.i ; vertices buffer in memory
Protected *PtrF.Triangle,*TriangleBuffer.i ; Faces buffer in memory
Protected newmesh.i ; Procedure Result
Protected i.i,v1.i,v2.i,v3.i
; Restore the good set of meshdatas
Select solid
Case #tetrahedron
Restore tetrahedron
Case #cube
Restore cube
Case #octahedron
Restore octahedron
Case #dodecahedron
Restore dodecahedron
Case #icosahedron
Restore icosahedron
Default
ProcedureReturn -1
EndSelect
; Read number of vertices and triangles
Read nbVert
Read nbTri
; Allocate the needed memory for vertices
*vertexBuffer = AllocateMemory(SizeOf(Vertex)*nbVert)
*PtrV = *vertexBuffer
; Read and store vertices position, normals, uv coords
For i = 1 To nbVert
Read.f x
Read.f y
Read.f z
Read.f nx
Read.f ny
Read.f nz
Read.f u
Read.f v
*PtrV\px = x * sizex
*PtrV\py = y * sizey
*PtrV\pz = z * sizez
*PtrV\nx = nx
*PtrV\ny = ny
*PtrV\nz = nz
*PtrV\couleur = Color
*PtrV\u = uorigin + (u * uscale)
*PtrV\v = vorigin + (v * vscale)
*PtrV + SizeOf(Vertex)
Next i
; Allocate the needed memory for faces
*TriangleBuffer=AllocateMemory(SizeOf(Triangle)*nbTri)
*PtrF=*TriangleBuffer
;Read and store faces infos
For i=1 To nbTri
Read.i v1
Read.i v2
Read.i v3
*PtrF\f1=v1
*PtrF\f2=v2
*PtrF\f3=v3
*PtrF + SizeOf(Triangle)
Next i
; Create mesh from stored infos
newmesh = CreateMesh(#PB_Any,sizex)
If IsMesh(newmesh)
SetMeshData(newmesh,#PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color,*vertexBuffer,nbVert)
SetMeshData(newmesh,#PB_Mesh_Face,*TriangleBuffer,nbTri)
; and don't forget to free memory
FreeMemory(*vertexBuffer)
FreeMemory(*TriangleBuffer)
ProcedureReturn newmesh
Else
; even if "createMesh" has failed
FreeMemory(*vertexBuffer)
FreeMemory(*TriangleBuffer)
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i CreateCylinderMesh(nbSides.i = 8,height.f = 1,radius.f = 1,coul.i = $FFFFFF)
Protected *PtrV.Vertex,*vertexBuffer.i ; vertices buffer in memory
Protected *PtrF.Triangle,*TriangleBuffer.i ; Faces buffer in memory
Protected newmesh.i ; Procedure Result
Protected i.i,nbVert.i,nbTri
Protected h2.f,theta.f
If nbSides<3
ProcedureReturn 0
EndIf
h2 = height / 2.0
nbVert = 4*(nbSides+1)+2
*vertexBuffer = AllocateMemory(SizeOf(Vertex)*nbVert)
*PtrV.Vertex = *vertexBuffer
;Sommet en bas du cylindre
For i = 0 To nbSides
theta =2*#PI*i/nbSides
*PtrV\px = radius*Cos(theta)
*PtrV\py = -h2
*PtrV\pz = radius*Sin(theta)
*PtrV\nx = Cos(theta)
*PtrV\ny = 0
*PtrV\nz = Sin(theta)
*PtrV\couleur = Coul
*PtrV\u = Theta / (2.0*#PI)
*PtrV\v = 0
*PtrV + SizeOf(Vertex)
Next i
;Sommet en haut du cylindre
For i = 0 To nbSides
theta =2*#PI*i/nbSides
*PtrV\px = radius*Cos(theta)
*PtrV\py = h2
*PtrV\pz = radius*Sin(theta)
*PtrV\nx = Cos(theta)
*PtrV\ny = 0
*PtrV\nz = Sin(theta)
*PtrV\couleur = Coul
*PtrV\u = Theta / (2.0*#PI)
*PtrV\v = 1
*PtrV + SizeOf(Vertex)
Next i
;Sommet face bas du cylindre
For i = 0 To nbSides
theta =2*#PI*i/nbSides
*PtrV\px = radius*Cos(theta)
*PtrV\py = -h2
*PtrV\pz = radius*Sin(theta)
*PtrV\nx = 0
*PtrV\ny = -1
*PtrV\nz = 0
*PtrV\couleur = Coul
*PtrV\u = Theta / (2.0*#PI)
*PtrV\v = 1
*PtrV + SizeOf(Vertex)
Next i
;Sommet face haut du cylindre
For i = 0 To nbSides
theta =2*#PI*i/nbSides
*PtrV\px = radius*Cos(theta)
*PtrV\py = h2
*PtrV\pz = radius*Sin(theta)
*PtrV\nx = 0
*PtrV\ny = 1
*PtrV\nz = 0
*PtrV\couleur = Coul
*PtrV\u = Theta / (2.0*#PI)
*PtrV\v = 1
*PtrV + SizeOf(Vertex)
Next i
;Centre bas
*PtrV\px = 0
*PtrV\py = -h2
*PtrV\pz = 0
*PtrV\nx = 0
*PtrV\ny = -1
*PtrV\nz = 0
*PtrV\couleur = Coul
*PtrV\u = 0.5
*PtrV\v = 0.5
*PtrV + SizeOf(Vertex)
;Centre haut
*PtrV\px = 0
*PtrV\py = h2
*PtrV\pz = 0
*PtrV\nx = 0
*PtrV\ny = 1
*PtrV\nz = 0
*PtrV\couleur = Coul
*PtrV\u = 0.5
*PtrV\v = 0.5
;Les facettes
nbTri = 4*nbSides
*TriangleBuffer=AllocateMemory(SizeOf(Triangle)*nbTri)
*PtrF.Triangle=*TriangleBuffer
For i=0 To nbSides-1
*PtrF\f3=i
*PtrF\f2=i + 1
*PtrF\f1=nbSides + i + 2
*PtrF + SizeOf(Triangle)
*PtrF\f1=i
*PtrF\f3=nbSides + i + 2
*PtrF\f2=nbSides + i + 1
*PtrF + SizeOf(Triangle)
Next i
;Face bas
For i=0 To nbSides-1
*PtrF\f1= 4 * nbSides + 4
*PtrF\f2= 2 * nbSides + 2 + i
*PtrF\f3= 2 * nbSides + 3 + i
*PtrF + SizeOf(Triangle)
Next i
;Face Haut
For i=0 To nbSides-1
*PtrF\f1= 4 * nbSides + 5
*PtrF\f3= 3 * nbSides + 3 + i
*PtrF\f2= 3 * nbSides + 4 + i
*PtrF + SizeOf(Triangle)
Next i
; Create mesh from stored infos
newmesh = CreateMesh(#PB_Any,100)
If IsMesh(newmesh)
SetMeshData(newmesh,#PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color,*vertexBuffer,nbVert)
SetMeshData(newmesh,#PB_Mesh_Face,*TriangleBuffer,nbTri)
; and don't forget to free memory
FreeMemory(*vertexBuffer)
FreeMemory(*TriangleBuffer)
ProcedureReturn newmesh
Else
; even if "createMesh" has failed
FreeMemory(*vertexBuffer)
FreeMemory(*TriangleBuffer)
ProcedureReturn -1
EndIf
EndProcedure
DisableExplicit
;- ---- Main loop ----
;-Mesh
; Change parameters 2 to 8 to test the effects on size and texturing
myTetraMesh.i = CreatePlatonicMesh(#tetrahedron,3,3,3)
; myTetraMesh.i = CreateCylinderMesh(12,3,2)
myCubeMesh.i = CreatePlatonicMesh(#cube,3,3,3)
myOctaMesh.i = CreatePlatonicMesh(#octahedron,3,3,3)
myDodecaMesh.i = CreatePlatonicMesh(#dodecahedron,3,3,3)
myIcosaMesh.i = CreatePlatonicMesh(#icosahedron,3,3,3)
;-Entity
CreateEntity(0,MeshID(myTetraMesh),#PB_Material_None)
CreateEntity(1,MeshID(myCubeMesh),#PB_Material_None)
CreateEntity(2,MeshID(myOctaMesh),#PB_Material_None)
CreateEntity(3,MeshID(myDodecaMesh),#PB_Material_None)
CreateEntity(4,MeshID(myIcosaMesh),#PB_Material_None)
EntityLocate(0,5,5,0)
EntityLocate(1,-5,5,0)
EntityLocate(2,10,-5,0)
EntityLocate(3,0,-5,0)
EntityLocate(4,-10,-5,0)
;-Camera
CreateCamera(0, 0, 0 , 100 , 100)
MoveCamera(0,0,0,-30)
CameraLookAt(0,0,0,0)
viewlabel.s = "Platonic Solids"
;-Light
AmbientColor(RGB(105,105,105))
CreateLight(0,RGB(160,160,255),200,300,0)
CreateLight(1,RGB(255,127,0),-200,-200,200)
pas.f = 0.8
angle.f = 0
Repeat
If fullscreen = 0
While WindowEvent() : Wend
EndIf
; Rotate solids, rotate! Oh, you're so gorgeous... ;)
Angle + Pas
RotateEntity(0, angle,angle/2,-angle)
RotateEntity(1, angle/2,-angle,angle)
RotateEntity(2, -angle,angle,angle/2)
RotateEntity(3, -angle,angle/2,angle)
RotateEntity(4, angle,-angle/2,-angle)
; Manage camera views
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
CameraLocate(0,EntityX(0),EntityY(0),EntityZ(0) - 10)
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))
viewlabel = "Tetrahedron"
EndIf
If KeyboardReleased(#PB_Key_F2)
CameraLocate(0,EntityX(1),EntityY(1),EntityZ(1) - 10)
CameraLookAt(0,EntityX(1),EntityY(1),EntityZ(1))
viewlabel = "Cube"
EndIf
If KeyboardReleased(#PB_Key_F3)
CameraLocate(0,EntityX(2),EntityY(2),EntityZ(2) - 10)
CameraLookAt(0,EntityX(2),EntityY(2),EntityZ(2))
viewlabel = "Octahedron"
EndIf
If KeyboardReleased(#PB_Key_F4)
CameraLocate(0,EntityX(3),EntityY(3),EntityZ(3) - 10)
CameraLookAt(0,EntityX(3),EntityY(3),EntityZ(3))
viewlabel = "Dodecahedron"
EndIf
If KeyboardReleased(#PB_Key_F5)
CameraLocate(0,EntityX(4),EntityY(4),EntityZ(4) - 10)
CameraLookAt(0,EntityX(4),EntityY(4),EntityZ(4))
viewlabel = "Icosahedron"
EndIf
If KeyboardReleased(#PB_Key_F6)
CameraLocate(0,0,0,-30)
CameraLookAt(0,0,0,0)
viewlabel = "Platonic Solids"
EndIf
If KeyboardReleased(#PB_Key_F7)
CameraMode=1-CameraMode
CameraRenderMode(0,CameraMode)
AmbientColor(RGB(105+cameramode*150,105+cameramode*150,105+cameramode*150))
EndIf
EndIf
; show it all
RenderWorld()
; Flip buffers to avoid tearing
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
;- Solids datas
DataSection:
tetrahedron:
; Nb sommets / Nb faces
Data.i 10,4
; Vertices: pos / normals / uv
Data.f 0.817497,0.578350,0
Data.f 0,1,0
Data.f 0.5,0.5
Data.f -0.815497,0.578350,0
Data.f 0,1,0
Data.f 0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0,0.577351,0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0,0.577351,-0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0.816496,-0.577351,0
Data.f 0.5,1.5
Data.f 0.817497,0.578350,0
Data.f 0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,-0.815497
Data.f -0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f -0.815497,0.578350,0
Data.f -0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,0.817497
Data.f -0.816496,-0.577351,0
Data.f 0.5,1.5
; Faces
Data.i 0,1,2
Data.i 1,0,3
Data.i 4,6,5
Data.i 7,9,8
cube:
; Nb sommets / Nb faces
Data.i 24,12
; Vertices: pos / normals / uv
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,1
Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,1
Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,0
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,0
Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,0
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,0
Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,1
Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,1
Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,0
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,0
Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,1
Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,1
Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,0
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.f 0,0
Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.f 0,1
Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.f 1,0
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.f 1,1
Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.f 1,0
; Faces
Data.i 2,1,0
Data.i 0,3,2
Data.i 6,5,4
Data.i 4,7,6
Data.i 10,9,8
Data.i 8,11,10
Data.i 14,13,12
Data.i 12,15,14
Data.i 18,17,16
Data.i 16,19,18
Data.i 22,21,20
Data.i 20,23,22
octahedron:
; Nb sommets / Nb faces
Data.i 18,8
; Vertices: pos / normals / uv
Data.f 0,0.708107,0.708107
Data.f 0,1,0
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0,1,0
Data.f 0,1.5
Data.f 1.001000,0,0
Data.f 1,0,0
Data.f 0.5,1
Data.f 0,-0.706107,0.708107
Data.f 0,0,1
Data.f -0.5,1
Data.f -0.999000,0,0
Data.f -1,0,0
Data.f 0,1.5
Data.f 0,-0.706107,-0.706107
Data.f 0,0,-1
Data.f -0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,0.816496
Data.f 0,0.5
Data.f 0,0.708107,0.708107
Data.f 0.577350,0,0.816496
Data.f 0.5,1
Data.f 0,0.708107,0.708107
Data.f -0.577350,0,0.816496
Data.f 0.5,1
Data.f -0.999000,0,0
Data.f -0.577350,0.816496,0
Data.f -0.5,1
Data.f 0,0.708107,-0.706107
Data.f -0.577350,0,-0.816496
Data.f 0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,-0.816496
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0.577350,0,-0.816496
Data.f 0.5,1
Data.f 0,-0.706107,-0.706107
Data.f 0.577350,-0.816496,0
Data.f 0,1.5
Data.f 0,-0.706107,0.708107
Data.f 0.577350,-0.816496,0
Data.f 0,0.5
Data.f -0.999000,0,0
Data.f -0.577350,-0.816496,0
Data.f -0.5,1
Data.f 0,-0.706107,0.708107
Data.f -0.577350,-0.816496,0
Data.f 0,0.5
Data.f 0,-0.706107,-0.706107
Data.f -0.577350,-0.816496,0
Data.f 0,1.5
; Faces
Data.i 1,0,2
Data.i 6,7,3
Data.i 3,8,4
Data.i 9,0,1
Data.i 4,10,5
Data.i 5,12,11
Data.i 2,14,13
Data.i 15,17,16
dodecahedron:
; Nb sommets / Nb faces
Data.i 72,36
; Vertices: pos / normals / uv
Data.f 0.357822,0.935172,0
Data.f 0,0.955423,0.295242
Data.f 0.190983,1
Data.f -0.355822,0.935172,0
Data.f 0,0.955423,-0.295242
Data.f -0.190983,1
Data.f 0.578350,0.578350,0.578350
Data.f 0.688191,0.587785,0.425325
Data.f 0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0,0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f 0,0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f -0.309017,1.309020
Data.f 0,0.357822,-0.933172
Data.f 0,0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.935172,0,0.357822
Data.f 1,0,0
Data.f 0.190983,1
Data.f 0.935172,0,-0.355822
Data.f 1,0,0
Data.f -0.190983,1
Data.f 0,-0.355822,-0.933172
Data.f 0,0,-1
Data.f -0.190983,1
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f -0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,-0.576350
Data.f -0.425325,-0.688191,-0.587785
Data.f -0.309017,1.309020
Data.f -0.355822,-0.933172,0
Data.f 0,-0.992447,0.122673
Data.f -0.190983,1
Data.f 0,-0.355822,0.935172
Data.f 0,-0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.979432,-0.201774,0
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.992447,0.122673,0
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.357822,0.935172,0
Data.f 0.850651,0.525731,0
Data.f 0,0.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0,0.357822,-0.933172
Data.f 0.525731,0,-0.850651
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.935172,0,-0.355822
Data.f 0.525731,0,-0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0,-0.355822,-0.933172
Data.f 0,-0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,-0.525731
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,0.525731
Data.f 0.190983,1
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,0.578350
Data.f -0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.525731,0,0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.576350,-0.576350,0.578350
Data.f -0.525731,0,0.850651
Data.f -0.309017,1.309020
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.850651,0.525731,0
Data.f 0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.576350,0.578350,-0.576350
Data.f -0.525731,0,-0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,-0.355822,0.935172
Data.f 0.525731,0,0.850651
Data.f -0.190983,1
; Faces
Data.i 0,3,2
Data.i 0,4,3
Data.i 0,1,4
Data.i 1,6,5
Data.i 1,7,6
Data.i 1,0,7
Data.i 20,8,9
Data.i 21,2,8
Data.i 22,23,2
Data.i 24,10,25
Data.i 26,11,10
Data.i 27,28,11
Data.i 29,12,13
Data.i 30,8,12
Data.i 31,9,8
Data.i 32,14,33
Data.i 34,15,14
Data.i 35,36,15
Data.i 15,16,17
Data.i 15,37,16
Data.i 15,39,38
Data.i 40,18,14
Data.i 41,19,18
Data.i 42,43,19
Data.i 44,46,45
Data.i 47,49,48
Data.i 50,52,51
Data.i 19,53,18
Data.i 19,55,54
Data.i 19,57,56
Data.i 58,10,14
Data.i 59,60,10
Data.i 61,63,62
Data.i 64,65,2
Data.i 66,68,67
Data.i 69,71,70
icosahedron:
; Nb sommets / Nb faces
Data.i 42,20
; Vertices: pos / normals / uv
Data.f 0,0.851651,0.526731
Data.f 0,1,0
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0,1,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.356822,0.934172,0
Data.f 0.5,1
Data.f 0.526731,0,0.851651
Data.f 0.810146,0,0.586227
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f 0,0,1
Data.f 0,1.309020
Data.f -0.849651,0.526731,0
Data.f -0.934172,0.356822,0
Data.f 0,0.690983
Data.f -0.524731,0,-0.849651
Data.f -0.810146,0,-0.586227
Data.f -0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0,0,-1
Data.f 0,0.690983
Data.f 0.851651,-0.524731,0
Data.f 0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0,-0.356822,-0.934172
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f 0,-0.707107,0.707107
Data.f 0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,0.577350
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f 0.526731,0,0.851651
Data.f 0,0.356822,0.934172
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0,0.356822,0.934172
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.577350,0.577350,0.577350
Data.f 0.5,1
Data.f 0,0.851651,0.526731
Data.f -0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f -0.849651,0.526731,0
Data.f -0.356822,0.934172,0
Data.f -0.5,1
Data.f 0,0.851651,-0.524731
Data.f -0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f -0.524731,0,-0.849651
Data.f 0,0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,0.851651,-0.524731
Data.f 0,0.356822,-0.934172
Data.f 0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0.577350,0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,-0.577350
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,0.356822
Data.f 0,0.690983
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,-0.356822
Data.f 0,0.690983
Data.f 0.526731,0,-0.849651
Data.f 0.934172,0,-0.356822
Data.f -0.5,1
Data.f -0.524731,0,-0.849651
Data.f 0,-0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f 0.526731,0,-0.849651
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,-0.524731,0
Data.f 0.356822,-0.934172,0
Data.f 0.5,1
Data.f 0,-0.849651,-0.524731
Data.f 0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.356822,-0.934172,0
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f -0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0,-0.356822,0.934172
Data.f -0.5,1
Data.f 0.526731,0,0.851651
Data.f 0,-0.356822,0.934172
Data.f 0,0.690983
Data.f -0.524731,0,0.851651
Data.f -0.577350,-0.577350,0.577350
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.934172,0,0.356822
Data.f 0.5,1
; Faces
Data.i 1,0,2
Data.i 12,13,3
Data.i 14,15,4
Data.i 16,17,5
Data.i 18,0,1
Data.i 5,19,6
Data.i 20,21,7
Data.i 22,24,23
Data.i 25,3,8
Data.i 26,8,27
Data.i 28,7,9
Data.i 29,30,8
Data.i 8,3,10
Data.i 31,33,32
Data.i 6,34,11
Data.i 35,37,36
Data.i 38,39,4
Data.i 10,40,11
Data.i 6,11,5
Data.i 5,11,41
EndDataSection
Re: Ogre3D basic obecjst movement examples?
for x64 (and x86) change the structure
Code: Select all
Structure Vertex
px.f
py.f
pz.f
nx.f
ny.f
nz.f
Couleur.l ; <<< L
U.f
V.f
EndStructurePlease correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
- Kwai chang caine
- Always Here

- Posts: 5522
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Ogre3D basic obecjst movement examples?
Splendid
Only the first code don't work for me (Black screen only), or surelly i don't know how it works
http://www.purebasic.fr/english/viewtop ... 69#p317169
But other...really splendid...
Thanks for sharing all this great works and showing the capacity of PB
Only the first code don't work for me (Black screen only), or surelly i don't know how it works
http://www.purebasic.fr/english/viewtop ... 69#p317169
But other...really splendid...
Thanks for sharing all this great works and showing the capacity of PB
The happiness is a road...Not a destination
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Ogre3D basic obecjst movement examples?
I posted a link to some simple OGRE .mesh shapes and told everyone to go crazy with them... I also told Fred he could distribute freely... In the ANNOUNCEMENTS section.
You need to supply your own textures!
http://www.purebasic.fr/english/viewtop ... 14&t=45326
shameless self bump!
You need to supply your own textures!
http://www.purebasic.fr/english/viewtop ... 14&t=45326
shameless self bump!

