StaticGeometry + physics

Everything related to 3D programming
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

StaticGeometry + physics

Post by Olby »

After a quick test I can confirm absence of physics support in static geometry; collision is removed once entities are added to the stat. geom. pool. This is a major show stopper and unless there is a way to do it static geometry in it's current state is quite useless. Please test the code to confirm it's not an issue with my code.

Code: Select all

; Conclusion StaticGeom does not support physics

#CamSpeed		=5.5
#MouseSpeed	=0.2
#ResX				=800
#ResY				=600
#Title			="PB3D (Hold space to add random physics entities)"

If InitEngine3D(#PB_Engine3D_DebugOutput)
	InitMouse()
	InitKeyboard()
	InitSprite()
	If OpenWindow(0,0,0,#ResX,#ResY,#Title,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
		If OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0))
			
			Add3DArchive(".",#PB_3DArchive_FileSystem)
			Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures\",#PB_3DArchive_FileSystem)
			Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\GUI",#PB_3DArchive_FileSystem)
			Parse3DScripts()
			
			WorldShadows(#PB_Shadow_Additive)
			
			CreateCamera(0,0,0,WindowWidth(0),WindowHeight(0))
			CameraBackColor(0,RGB(0, 123, 191))
			MoveCamera(0,10,30,160)
			
			CreateLight(0,RGB(255, 255, 95),-50,50,100)
			
			OpenWindow3D(0,10,10,220,100,"Engine Stats")
			TextGadget3D(0,10,10,200,30,"")
			TextGadget3D(1,10,40,200,30,"")
			ShowGUI(255,0)
			
			CreateMaterial(0,TextureID(LoadTexture(#PB_Any,"ground_diffuse.png")))
			
			CreateCube(0,1)
			CreateSphere(1,1)
			
			CreateEntity(0,MeshID(0),MaterialID(0))
			CreateEntity(1,MeshID(0),MaterialID(0))
			
			ScaleEntity(0,100,10,100)
			ScaleEntity(1,10,10,100)
			RotateEntity(0,0,0,-20)
			MoveEntity(1,50,-5,0)
			
			EntityPhysicBody(0,#PB_Entity_StaticBody,1,0,5.0)
			EntityPhysicBody(1,#PB_Entity_StaticBody,1,5,0.5)
			
			If MessageRequester("PB3D","Enable Static Geometry?",#PB_MessageRequester_YesNo)=#PB_MessageRequester_Yes
				CreateStaticGeometry(0,200,200,200,#True)
				AddStaticGeometryEntity(0,EntityID(0),0,0,0,100,10,100,0,0,20)
				AddStaticGeometryEntity(0,EntityID(1),50,-5,0,10,10,100)
				BuildStaticGeometry(0)
				FreeEntity(0)
				FreeEntity(1)
				SetWindowTitle(0,#Title+" STATIC GEOMETRY IS ON!")
			EndIf
		
			Define.f CamMX,CamMY,MouseLX,MouseLY
			Repeat
				ExamineKeyboard()
				ExamineMouse()
				
				MouseLX=-(MouseDeltaX()*#MouseSpeed)
				MouseLY=-(MouseDeltaY()*#MouseSpeed)
				If KeyboardPushed(#PB_Key_Left)
					CamMX=-#CamSpeed
				ElseIf KeyboardPushed(#PB_Key_Right)
					CamMX=#CamSpeed
				Else
					CamMX=0
				EndIf
				If KeyboardPushed(#PB_Key_Up)
					CamMY=-#CamSpeed
				ElseIf KeyboardPushed(#PB_Key_Down)
					CamMY=#CamSpeed
				Else
					CamMY=0
				EndIf
				
				If KeyboardPushed(#PB_Key_Space)
					phys=Random(1)
					ent=CreateEntity(#PB_Any,MeshID(phys),MaterialID(0),Random(100)-50,100,Random(100)-50)
					ScaleEntity(ent,5,5,5)
					If phys=0
						EntityPhysicBody(ent,#PB_Entity_BoxBody)
					Else
						EntityPhysicBody(ent,#PB_Entity_SphereBody)
					EndIf
				EndIf
				
				RotateCamera(0,MouseLY,MouseLX,0,#PB_Relative)
				MoveCamera(0,CamMX,0,CamMY)

				RenderWorld()
				FlipBuffers()
				SetGadgetText3D(0,"FPS: "+StrF(Engine3DFrameRate(#PB_Engine3D_Current)))
				SetGadgetText3D(1,"Tris: "+StrF(CountRenderedTriangles()))
				
			Until WindowEvent()=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
			
		EndIf
	EndIf
EndIf
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: StaticGeometry + physics

Post by applePi »

as you said unless we comment the lines
FreeEntity(0)
FreeEntity(1)

PS: but if we give the balls and cubes meshes different than static geo then we can FreeEntity(0) and FreeEntity(1) without affecting physics
i am still thinking about the static geo and i wish we can rotate it

Code: Select all

; Conclusion StaticGeom does not support physics

#CamSpeed      =5.5
#MouseSpeed   =0.2
#ResX            =800
#ResY            =600
#Title         ="PB3D (Hold space to add random physics entities)"

If InitEngine3D(#PB_Engine3D_DebugOutput)
   InitMouse()
   InitKeyboard()
   InitSprite()
   If OpenWindow(0,0,0,#ResX,#ResY,#Title,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
      If OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0))
         
         Add3DArchive(".",#PB_3DArchive_FileSystem)
         Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures\",#PB_3DArchive_FileSystem)
         Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\GUI",#PB_3DArchive_FileSystem)
         Parse3DScripts()
         
         WorldShadows(#PB_Shadow_Additive)
         
         CreateCamera(0,0,0,WindowWidth(0),WindowHeight(0))
         CameraBackColor(0,RGB(0, 123, 191))
         MoveCamera(0,10,30,160)
         
         CreateLight(0,RGB(255, 255, 95),-50,50,100)
         
         OpenWindow3D(0,10,10,220,100,"Engine Stats")
         TextGadget3D(0,10,10,200,30,"")
         TextGadget3D(1,10,40,200,30,"")
         ShowGUI(255,0)
         
         CreateMaterial(0,TextureID(LoadTexture(#PB_Any,"ground_diffuse.png")))
         
         CreateCube(0,1)
         CreateSphere(1,1)
         
         CreateEntity(0,MeshID(0),MaterialID(0))
         CreateEntity(1,MeshID(0),MaterialID(0))
         
         CreateEntity(2,MeshID(0),MaterialID(0))
         CreateEntity(3,MeshID(0),MaterialID(0))
         ScaleEntity(2,100,10,100)
         ScaleEntity(3,10,10,100)
         RotateEntity(2,0,0,-20)
         MoveEntity(3,50,-5,0)
         
         ScaleEntity(0,100,10,100)
         ScaleEntity(1,10,10,100)
         RotateEntity(0,0,0,-20)
         MoveEntity(1,50,-5,0)
         
         EntityPhysicBody(0,#PB_Entity_StaticBody,1,0,5.0)
         EntityPhysicBody(1,#PB_Entity_StaticBody,1,5,0.5)
         EntityPhysicBody(2,#PB_Entity_StaticBody,1,0,5.0)
         EntityPhysicBody(3,#PB_Entity_StaticBody,1,5,0.5)
         
         If MessageRequester("PB3D","Enable Static Geometry?",#PB_MessageRequester_YesNo)=#PB_MessageRequester_Yes
            CreateStaticGeometry(0,200,200,200,#True)
            AddStaticGeometryEntity(0,EntityID(2),0,0,0,100,10,100,0,0,20)
            AddStaticGeometryEntity(0,EntityID(3),50,-5,0,10,10,100)
            BuildStaticGeometry(0)
            FreeEntity(0)
            FreeEntity(1)
            SetWindowTitle(0,#Title+" STATIC GEOMETRY IS ON!")
         EndIf
      
         Define.f CamMX,CamMY,MouseLX,MouseLY
         Repeat
            ExamineKeyboard()
            ExamineMouse()
            
            MouseLX=-(MouseDeltaX()*#MouseSpeed)
            MouseLY=-(MouseDeltaY()*#MouseSpeed)
            If KeyboardPushed(#PB_Key_Left)
               CamMX=-#CamSpeed
            ElseIf KeyboardPushed(#PB_Key_Right)
               CamMX=#CamSpeed
            Else
               CamMX=0
            EndIf
            If KeyboardPushed(#PB_Key_Up)
               CamMY=-#CamSpeed
            ElseIf KeyboardPushed(#PB_Key_Down)
               CamMY=#CamSpeed
            Else
               CamMY=0
            EndIf
            
            If KeyboardPushed(#PB_Key_Space)
               phys=Random(1)
               ent=CreateEntity(#PB_Any,MeshID(phys),MaterialID(0),Random(100)-50,100,Random(100)-50)
               ScaleEntity(ent,5,5,5)
               If phys=0
                  EntityPhysicBody(ent,#PB_Entity_BoxBody)
               Else
                  EntityPhysicBody(ent,#PB_Entity_SphereBody)
               EndIf
            EndIf
            
            RotateCamera(0,MouseLY,MouseLX,0,#PB_Relative)
            MoveCamera(0,CamMX,0,CamMY)

            RenderWorld()
            FlipBuffers()
            SetGadgetText3D(0,"FPS: "+StrF(Engine3DFrameRate(#PB_Engine3D_Current)))
            SetGadgetText3D(1,"Tris: "+StrF(CountRenderedTriangles()))
            
         Until WindowEvent()=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
         
      EndIf
   EndIf
EndIf
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: StaticGeometry + physics

Post by Olby »

applePi wrote:as you said unless we comment the lines
FreeEntity(0)
FreeEntity(1)

PS: but if we give the balls and cubes meshes different than static geo then we can FreeEntity(0) and FreeEntity(1) without affecting physics
i am still thinking about the static geo and i wish we can rotate it

Code: Select all

; Conclusion StaticGeom does not support physics

#CamSpeed      =5.5
#MouseSpeed   =0.2
#ResX            =800
#ResY            =600
#Title         ="PB3D (Hold space to add random physics entities)"

If InitEngine3D(#PB_Engine3D_DebugOutput)
   InitMouse()
   InitKeyboard()
   InitSprite()
   If OpenWindow(0,0,0,#ResX,#ResY,#Title,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
      If OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0))
         
         Add3DArchive(".",#PB_3DArchive_FileSystem)
         Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures\",#PB_3DArchive_FileSystem)
         Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\GUI",#PB_3DArchive_FileSystem)
         Parse3DScripts()
         
         WorldShadows(#PB_Shadow_Additive)
         
         CreateCamera(0,0,0,WindowWidth(0),WindowHeight(0))
         CameraBackColor(0,RGB(0, 123, 191))
         MoveCamera(0,10,30,160)
         
         CreateLight(0,RGB(255, 255, 95),-50,50,100)
         
         OpenWindow3D(0,10,10,220,100,"Engine Stats")
         TextGadget3D(0,10,10,200,30,"")
         TextGadget3D(1,10,40,200,30,"")
         ShowGUI(255,0)
         
         CreateMaterial(0,TextureID(LoadTexture(#PB_Any,"ground_diffuse.png")))
         
         CreateCube(0,1)
         CreateSphere(1,1)
         
         CreateEntity(0,MeshID(0),MaterialID(0))
         CreateEntity(1,MeshID(0),MaterialID(0))
         
         CreateEntity(2,MeshID(0),MaterialID(0))
         CreateEntity(3,MeshID(0),MaterialID(0))
         ScaleEntity(2,100,10,100)
         ScaleEntity(3,10,10,100)
         RotateEntity(2,0,0,-20)
         MoveEntity(3,50,-5,0)
         
         ScaleEntity(0,100,10,100)
         ScaleEntity(1,10,10,100)
         RotateEntity(0,0,0,-20)
         MoveEntity(1,50,-5,0)
         
         EntityPhysicBody(0,#PB_Entity_StaticBody,1,0,5.0)
         EntityPhysicBody(1,#PB_Entity_StaticBody,1,5,0.5)
         EntityPhysicBody(2,#PB_Entity_StaticBody,1,0,5.0)
         EntityPhysicBody(3,#PB_Entity_StaticBody,1,5,0.5)
         
         If MessageRequester("PB3D","Enable Static Geometry?",#PB_MessageRequester_YesNo)=#PB_MessageRequester_Yes
            CreateStaticGeometry(0,200,200,200,#True)
            AddStaticGeometryEntity(0,EntityID(2),0,0,0,100,10,100,0,0,20)
            AddStaticGeometryEntity(0,EntityID(3),50,-5,0,10,10,100)
            BuildStaticGeometry(0)
            FreeEntity(0)
            FreeEntity(1)
            SetWindowTitle(0,#Title+" STATIC GEOMETRY IS ON!")
         EndIf
      
         Define.f CamMX,CamMY,MouseLX,MouseLY
         Repeat
            ExamineKeyboard()
            ExamineMouse()
            
            MouseLX=-(MouseDeltaX()*#MouseSpeed)
            MouseLY=-(MouseDeltaY()*#MouseSpeed)
            If KeyboardPushed(#PB_Key_Left)
               CamMX=-#CamSpeed
            ElseIf KeyboardPushed(#PB_Key_Right)
               CamMX=#CamSpeed
            Else
               CamMX=0
            EndIf
            If KeyboardPushed(#PB_Key_Up)
               CamMY=-#CamSpeed
            ElseIf KeyboardPushed(#PB_Key_Down)
               CamMY=#CamSpeed
            Else
               CamMY=0
            EndIf
            
            If KeyboardPushed(#PB_Key_Space)
               phys=Random(1)
               ent=CreateEntity(#PB_Any,MeshID(phys),MaterialID(0),Random(100)-50,100,Random(100)-50)
               ScaleEntity(ent,5,5,5)
               If phys=0
                  EntityPhysicBody(ent,#PB_Entity_BoxBody)
               Else
                  EntityPhysicBody(ent,#PB_Entity_SphereBody)
               EndIf
            EndIf
            
            RotateCamera(0,MouseLY,MouseLX,0,#PB_Relative)
            MoveCamera(0,CamMX,0,CamMY)

            RenderWorld()
            FlipBuffers()
            SetGadgetText3D(0,"FPS: "+StrF(Engine3DFrameRate(#PB_Engine3D_Current)))
            SetGadgetText3D(1,"Tris: "+StrF(CountRenderedTriangles()))
            
         Until WindowEvent()=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
         
      EndIf
   EndIf
EndIf
Without freeing the entities we keep unnecessary duplicates and (in case of larger levels) consume lots of RAM for no particular reason. I wish static geom could be expanded with full physics engine integration (along with ray casting, etc.).
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: StaticGeometry + physics

Post by DK_PETER »

Olby wrote:
applePi wrote:as you said unless we comment the lines
FreeEntity(0)
FreeEntity(1)

PS: but if we give the balls and cubes meshes different than static geo then we can FreeEntity(0) and FreeEntity(1) without affecting physics
i am still thinking about the static geo and i wish we can rotate it
Without freeing the entities we keep unnecessary duplicates and (in case of larger levels) consume lots of RAM for no particular reason. I wish static geom could be expanded with full physics engine integration (along with ray casting, etc.).
Nothing is wrong with the code. I've been sitting and messing around with static geo for awhile now and my preliminary conclusion is: Pure eye-candy - nothing else.
Yeah..I'd go for physics, movement and rotation too.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: StaticGeometry + physics

Post by PMV »

Just searched a little bit, because i haven't done anything with the
physic-stuff yet ... but the result is really simple:

StaticGeometry() is from OGRE3D, the static geometry class.
It is designed to save overhead, especially from the CPU.
So the result data is just meant to be used for the render-process.
The complete physic stuff is not OGRE, as it is called bullet.
But bullet can use the information from OGRE. As the static
geometry just have graphic-data and is already "pre-rendered",
there is no possibility to get the needed data for bullet, that
calculates physic-stuff with the CPU.

So, maybe there is a function where you can use bullet
without creating a complete ogre-entity. Haven't looked
into the functionality of OGREBullet yet. But if you just hide
an entity, then there shouldn't be much performance issues. :)

MFG PMV
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: StaticGeometry + physics

Post by Olby »

PMV wrote:Just searched a little bit, because i haven't done anything with the
physic-stuff yet ... but the result is really simple:

StaticGeometry() is from OGRE3D, the static geometry class.
It is designed to save overhead, especially from the CPU.
So the result data is just meant to be used for the render-process.
The complete physic stuff is not OGRE, as it is called bullet.
But bullet can use the information from OGRE. As the static
geometry just have graphic-data and is already "pre-rendered",
there is no possibility to get the needed data for bullet, that
calculates physic-stuff with the CPU.

So, maybe there is a function where you can use bullet
without creating a complete ogre-entity. Haven't looked
into the functionality of OGREBullet yet. But if you just hide
an entity, then there shouldn't be much performance issues. :)

MFG PMV
You're right. What they should do is add a flag to copy the physics body along with the visuals. This would allow one to create static geometry batches with underlying physics support. Something like this:
AddStaticGeometryEntity(#StaticGeometry, EntityID, x, y, z [, ScaleX, ScaleY, ScaleZ [, RotationX, RotationY, RotationZ [, Flags]]])
Where flag is: #PB_StaticGeometry_Collision and more.
Physics body should also be moved, scaled and rotated accordingly, as well as copy all physical characteristics of the source entity i.e. mass, friction and restitution.
Obviously once the entity is added to a static world it should only use the #PB_Entity_StaticBody type.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: StaticGeometry + physics

Post by Bananenfreak »

@Olby:
Thank you for this code :)

If physics Body would be changed to StaticBody, there were no Need for moving, scaling,... the physics Body. You add a Entity to a static geometry (for example the staticgeometry is defined as physically static geometry with a flag) then the physics Body is changed to StaticBody, whatever entities got before as physics Body, the Body is redefined as StaticBody, you can say: a new Body... ("simple and easier then other Solutions").
But is it possible to add physics to static geometry?
Image
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: StaticGeometry + physics

Post by PMV »

Bananenfreak wrote:But is it possible to add physics to static geometry?
No. An entity doesn't have a physic body per default, as it is just OGRE.
The physic-body is created through a call to bullet. That call is, i think, reflected
by the function EntityPhysicBody() and DisableEntityBody(). And that is only
possible for a previously created entity. For me, it sounds good to add a
flag to EntityPhysicBody() like #PB_Entity_Hidden.

To rotate and move an entity, you still have just the entity-functions. So
you still have to create an entity through OGRE. But it should be
possible to complete remove that entity from the render-queue and maybe
remove some overhead, that is not needed to save a little bit of memory.
But StaticGeometry() and EntityPhysicBody() are needed both as they have
complete different tasks. :wink:

MFG PMV
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: StaticGeometry + physics

Post by Olby »

Bananenfreak wrote:@Olby:
Thank you for this code :)

If physics Body would be changed to StaticBody, there were no Need for moving, scaling,... the physics Body. You add a Entity to a static geometry (for example the staticgeometry is defined as physically static geometry with a flag) then the physics Body is changed to StaticBody, whatever entities got before as physics Body, the Body is redefined as StaticBody, you can say: a new Body... ("simple and easier then other Solutions").
First of all there are two issues.

1. When you add an entity to static geometry it is reset and all of the previous move/scale/rotation calls are ignored and it reverts back to the original state (mesh). That's why it is important to have scale/rotate/move in the AddStaticGeometryEntity() command. If they implement physics support it should also align the physics body accordingly.

2. Unless they add parameters to set mass, friction and restitution when calling AddStaticGeometryEntity() it should copy this information from the entity which means EntityPhysicsBody() needs to be called on each entity to set its physical attributes.

3. I would prefer if any dynamic body type would automatically cast to #PB_Entity_StaticBody when added to static geometry.
Bananenfreak wrote:But is it possible to add physics to static geometry?
Why not? OGRE and Bullet are two separate frameworks. You can add anything you like to the physics scene even if it does not match with the visual representation. Even if the static geometry is culled and hidden physics bodies would still be there and register any collisions.
PMV wrote:
Bananenfreak wrote:But is it possible to add physics to static geometry?
No. An entity doesn't have a physic body per default, as it is just OGRE.
The physic-body is created through a call to bullet. That call is, i think, reflected
by the function EntityPhysicBody() and DisableEntityBody(). And that is only
possible for a previously created entity. For me, it sounds good to add a
flag to EntityPhysicBody() like #PB_Entity_Hidden.

To rotate and move an entity, you still have just the entity-functions. So
you still have to create an entity through OGRE. But it should be
possible to complete remove that entity from the render-queue and maybe
remove some overhead, that is not needed to save a little bit of memory.
But StaticGeometry() and EntityPhysicBody() are needed both as they have
complete different tasks. :wink:

MFG PMV
Yup, there should be a way to add invisible collision entities and also a way to debug them visually (i.e. if #PB_World_DebugBody is used they should be visible).
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: StaticGeometry + physics

Post by applePi »

my post above to pretend modifying olby code , are stupid , and have not appreciate what olby was trying to say, yes there is no physics with static geometry.
here is my suggestion away from static geometry suitable for cities like the city of Peter.
this is to use a terrain with the shape of a city building, as an example, use this city.png save it the same as the code
Image
to be used by DefineTerrainTile function, and you have a city with physics, but my city are upside down how to reverse it ?

Code: Select all

#CameraSpeed = 20
#TerrainMiniX = 0
#TerrainMiniY = 0
#TerrainMaxiX = 0
#TerrainMaxiY = 0
Define.f KeyX, KeyY, MouseX, MouseY


; OpenGL needs to have CG enabled to work (Linux and OS X have OpenGL by default)
;
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows Or Subsystem("OpenGL")
  Flags = #PB_Engine3D_EnableCG
CompilerEndIf

If InitEngine3D(Flags)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
ExamineDesktops()
win = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "use arrow keys and mouse", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(win),0,0,DesktopWidth(0), DesktopHeight(0))
    Add3DArchive(".", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/"       , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/nvidia" , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts"         , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/GUI"           , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
    
    WorldShadows(#PB_Shadow_Modulative, -1, RGB(105, 105, 105))
    
    ;- Light 
    ;
    light.l = CreateLight(#PB_Any ,RGB(255, 255, 255), 4000, 1200, 1000,#PB_Light_Directional)
    SetLightColor(light, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4)) 
    LightDirection(light ,0.55, -0.3, -0.75) 
    AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
        
    ;- Camera 
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0,  100, 500, 1500, #PB_Absolute)
    RotateCamera(0, -15, 0, 0 ,#PB_Absolute)
    CameraBackColor(0, RGB(5, 5, 10))
    
    ;----------------------------------
    ; terrain defintion
    SetupTerrains(LightID(Light), 200, #PB_Terrain_NormalMapping)
    ; initialize terrain 
    ;CreateTerrain(#Terrain, Size, WorldSize, Scale, NbLayers, Filename$, Extension$)
    CreateTerrain(0, 129, 1500, 100, 1, "terrain02", "Dat")
    ;set all texture will be use when terrrain will be constructed 
    ;AddTerrainTexture(#Terrain, Layer, WorldSize, DiffuseSpecular$, NormalHeight$)
    AddTerrainTexture(0,  0, 100, "dirt_grayrocky_diffusespecular.dds",  "dirt_grayrocky_normalheight.dds")
        
    ;construct terrains
    DefineTerrainTile(0, 0, 0, "city.png", 0, 0)  
    
    BuildTerrain(0)  
        
    ; enable shadow terrain
    TerrainRenderMode(0, #PB_Terrain_CastShadows)
        
    
    CreateSphere(1, 40)
    Global Ball = CreateEntity(#PB_Any, MeshID(1), #Null)
    MoveEntity(Ball, 100,520,0, #PB_Absolute)
    EntityRenderMode(Ball, #PB_Entity_CastShadow)
    
    ; SkyBox
    ;
    SkyBox("desert07.jpg")
    
    ShowGUI(128, 1) ; Display the GUI, semi-transparent and display the mouse cursor
    EnableWorldPhysics(1)
    TerrainPhysicBody(0, 0.2,2.0)
    EntityPhysicBody(Ball,#PB_Entity_SphereBody,6,3,5)
    
    WorldGravity(-220)
    Repeat
           
      If ExamineKeyboard()       
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
               
      EndIf
      ;CameraLocate(0, CameraX(0), PBO_GetTerrainHeight(0, CameraX(0), CameraZ(0)) + 20, CameraZ(0))
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative) 
      y.f+0.6
      z.f+0.2
      RotateEntity(Ball, -90, y, z ,#PB_Absolute)

      RenderWorld()
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape)   
    
    End 
   
Else
  MessageRequester("Error","Can't initialize engine3D")
EndIf
another approach is to use the example MP_Picture_to_3D.pb from MP3D library "C:\PureBasic\MP3D Demos\Extra"
add to the last line before End the "MP_SaveMesh("city.x",terrain)"
now run it and press space and choose city.png, then choose city.png again and it will display it as a 3D model, when you exit it will be saved as city.x , its size here 3MB and it will use city.png as texture.
now copy the city.x and city.png to the folder of OgreAssimpConverter and from prompt write OgreAssimpConverter city.x . so it will produce city_x.mesh and city_x.material wich refer to the city.png.
if you want to appreciate the beauty of this MP3D example download the model made by it and converted to mesh and material by OgreAssimpConverter from here
http://www.mediafire.com/?pd1mc36ij7zfnau
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: StaticGeometry + physics

Post by Bananenfreak »

So, the only thing we can do (now) is to Keep the first entity and hide it. The staticgeometry entity is rendered, but the hidden entity gets a physics Body.
The first entity is not rendered, or? So there is a provisional static geometry with physics (I mean Olby said this already...)
Image
Post Reply