3D tests (4.30)
3D tests (4.30)
I made an archiv with my 3D tests with 4.30 and old codes updated for 4.30.
http://herved25.free.fr/test/Demo3D.zip
http://herved25.free.fr/test/Demo3D.zip
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Really nice demos.
A great way to learn 3D game making in Purebasic.
Thanks a lot.
In the Rubick.pb, if I click on any area of the game the game freezes because of the debugger error catching which points to this line:
BTW, World.pb is fascinating. 
A great way to learn 3D game making in Purebasic.
Thanks a lot.
In the Rubick.pb, if I click on any area of the game the game freezes because of the debugger error catching which points to this line:
Code: Select all
SetWindowTitle(0,"Entité sélectionnée " + Str(PickX()) + " - " + Str(PickY()) + " - " + Str(PickZ()))
The specified window #Window is not initialized.Proud registered Purebasic user.
Because programming should be fun.
Because programming should be fun.
I made all my test in windowed modebyo wrote: In the Rubick.pb, if I click on any area of the game the game freezes because of the debugger error catching which points to this line:
Code: Select all
SetWindowTitle(0,"Entité sélectionnée " + Str(PickX()) + " - " + Str(PickY()) + " - " + Str(PickZ())) The specified window #Window is not initialized.
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Jaiqua follow ninja, just copy this code in the same folder (demo3D).
Code: Select all
#Deg2Rad = #PI/180
#Rad2Deg = 180/#PI
IncludeFile "Screen3DRequester.pb"
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
Add3DArchive("GUI\", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\schemes", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\imagesets", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\fonts", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\looknfeel", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\layouts", #PB_3DArchive_FileSystem)
Add3DArchive("Data\" , #PB_3DArchive_FileSystem)
Add3DArchive("Jaiqua\", #PB_3DArchive_FileSystem)
Add3DArchive("Ninja\", #PB_3DArchive_FileSystem)
Add3DArchive("Cube\", #PB_3DArchive_FileSystem)
Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
If Screen3DRequester()
Structure Vecteur
x.f
z.f
EndStructure
Declare Norme(*V.Vecteur)
Declare.f atan2f(y.f,x.f)
Declare.f CurveValue(actuelle.f, Cible.f, P.f)
Declare.f WrapValue(angle.f)
Declare.f CurveAngle( Actuelle.f , Cible.f , P.f)
;-Déclaration des variables
Define AngleY.f, Angle, AngleC.f, dist, Mode,Vitesse.f = 0.7, pas.f=0.13
Define.Vecteur Direction, Origine, Destination
Define.f KeyX, KeyY, MouseX, MouseY, AngleCamera,Px,Py,Pz,Pv=50
#Speed = 4
Macro DISTANCE(p1, p2)
Sqr((p1\x - p2\x) * (p1\x - p2\x) + (p1\z - p2\z) * (p1\z - p2\z))
EndMacro
Macro NEW_X(x, Angle, Distance)
((x) + Cos((Angle) * #Deg2Rad) * (Distance))
EndMacro
Macro NEW_Z(z, Angle, Distance)
((z) - Sin((Angle) * #Deg2Rad) * (Distance))
EndMacro
WorldShadows(#PB_Shadow_Additive) ; Set the shadow mode for the world
;-Create a plan
;
CreateMesh(1,100)
SetMeshData(1, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?PlanVertices, 4)
SetMeshData(1, #PB_Mesh_Face, ?PlanFaces, 2)
CreateMaterial(1, LoadTexture(1, "Background.png"))
CreateEntity (10, MeshID(1), MaterialID(1))
EntityRenderMode(1, 0) ; Disable shadow casting for this entity as it's our plan
ScaleEntity(10, 1000, 1, 1000)
MoveEntity(10, -500, -5, -500)
DisableMaterialLighting(1, #False)
;-Entité A
LoadMesh (0, "jaiqua.mesh")
CreateMaterial(0, LoadTexture(0, "blue_jaiqua.jpg"))
CreateEntity(0,MeshID(0),MaterialID(0))
ScaleEntity(0,4,4,4)
AnimateEntity(0, "Walk")
;-Entité B
LoadMesh (2, "Ninja.mesh")
CreateMaterial(2, LoadTexture(2, "nskingr.jpg"))
CreateEntity(2, MeshID(2), MaterialID(2))
ScaleEntity(2,0.4,0.4,0.4)
AnimateEntity(2, "Walk")
;-Camera
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 500, 190, 700)
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))
;-Light
AmbientColor(RGB(138,138,138))
CreateLight(0, RGB(255,255,255), 100, 400, 0)
;-Fog
Fog(RGB(128,128,128),128,10,2000)
;-Skybox
SkyBox("stevecube.jpg")
;-Window3D
OpenWindow3D(0,0,0,300,100,"Poursuite")
TextGadget3D(0,20,50,200,40,"Push 'F1'")
ShowGUI(128,1)
Repeat
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
Mode = 1 - Mode
If Mode
T$="use cursor or 'F1'"
Else
T$="Camera auto or 'F1'"
EndIf
SetGadgetText3D(0,T$)
EndIf
If Mode
If KeyboardPushed(#PB_Key_Left)
KeyX = -#Speed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #Speed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#Speed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #Speed
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_PageUp)
RollZ = 3
Else
RollZ = 0
EndIf
RotateCamera(0, MouseY, MouseX, RollZ,1)
MoveCamera (0, KeyX, 0, KeyY)
Else
AngleCamera = Curveangle(AngleCamera, AngleY-90, Pv)
Px = CurveValue(CameraX(0), NEW_X(EntityX(0), AngleCamera, 160), Pv)
Py = CurveValue(CameraY(0), EntityY(0) + 90, Pv)
Pz = CurveValue(CameraZ(0), NEW_Z(EntityZ(0), AngleCamera, 160), Pv)
CameraLocate(0, Px, Py, Pz)
CameraLookAt(0, EntityX(0), EntityY(0)+30, EntityZ(0))
EndIf
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX()/10
MouseY = -MouseDeltaY()/10
EndIf
;SetWindowTitle3D(0,Str(AngleC))
RotateEntity(2,0,AngleC,0)
EntityLocate(2,Cos(AngleC*#Deg2Rad)*400,-6,-Sin(AngleC*#Deg2Rad)*400)
AngleC+pas
Destination\x = EntityX(2)
Destination\z = EntityZ(2)
;Direction
Direction\x = Destination\x - EntityX(0)
Direction\z = Destination\z - EntityZ(0)
Angle=-atan2f(Direction\z, Direction\x) / #Deg2Rad
Norme(@Direction)
;Origine
Origine\x = EntityX(0)
Origine\z = EntityZ(0)
;Deplacement Entity
dist = DISTANCE(Destination, Origine)
AngleY=CurveAngle(AngleY,Angle-90,40)
RotateEntity(0,0,AngleY,0)
If dist < Vitesse
EntityLocate(0,NEW_X(EntityX(0),AngleY,dist),0,NEW_Z(EntityZ(0),AngleY,dist))
Else
EntityLocate(0,NEW_X(EntityX(0),AngleY+90,Vitesse),0,NEW_Z(EntityZ(0),AngleY+90,Vitesse))
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
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 )
Delta.f=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
Delta.f = EcartAngle( Actuelle , Cible )
If P > 1000 : P = 1000 : EndIf
Valeur.f = Actuelle + ( Delta * P / 1000 )
ProcedureReturn WrapValue( Valeur )
EndProcedure
Procedure.f CurveValue(actuelle.f, Cible.f, P.f)
;Calcule une valeur progressive allant de la valeur actuelle à la valeur cible
Define.f Delta
Delta = Cible - actuelle
If P > 1000.0 : P = 1000.0 : EndIf
ProcedureReturn (actuelle + ( Delta * P / 1000.0))
EndProcedure
Procedure Norme(*V.Vecteur)
Define.f Norme
Norme.f = Sqr(*V\x * *V\x + *V\z * *V\z)
If Norme
*V\x / Norme
*V\z / Norme
EndIf
EndProcedure
Procedure.f atan2f(y.f, x.f)
!fld dword[p.v_y]
!fld dword[p.v_x]
!fpatan
ProcedureReturn
EndProcedure
DataSection
PlanVertices:
; Note normals are important component to allow correct light support (and therefore shadow)
;
Data.f 0, 0, 0 ; Vertex 0
Data.f 1, 1, 1 ; Normals (perpendicular to the plan)
Data.f 0 , 0.33 ; UVCoordinate
Data.f 1, 0, 0 ; Vertex 1
Data.f 1,1,1 ; Normals
Data.f 0.33, 0.33 ; UVCoordinate
Data.f 1, 0, 1 ; Vertex 2
Data.f 1,1,1 ; Normals
Data.f 0.33, 0 ; UVCoordinate
Data.f 0, 0, 1 ; Vertex 3
Data.f 1,1,1 ; Normals
Data.f 0, 0 ; UVCoordinate
PlanFaces:
Data.w 2, 1, 0 ; bottom face (clockwise as it's reversed...)
Data.w 0, 3, 2
EndDataSectionPlease correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Chess.pb - crashes when you make it a window and click on it.
Dungeon.pb - crashes when you make it a window and click on it.
-> I think they all do it, it might have something to do with the lack of window boarder.
Rubick.pb / RubickNode.pb -
SetWindowTitle(0,"Entité sélectionnée " + Str(PickX()) + " - " +Str(PickY()) + " - " + Str(PickZ()))
The specified #Window is not initialized.
TestGadget3D.pb - I get a black screen.
Dungeon.pb - crashes when you make it a window and click on it.
-> I think they all do it, it might have something to do with the lack of window boarder.
Rubick.pb / RubickNode.pb -
SetWindowTitle(0,"Entité sélectionnée " + Str(PickX()) + " - " +Str(PickY()) + " - " + Str(PickZ()))
The specified #Window is not initialized.
TestGadget3D.pb - I get a black screen.
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:



