Yeah...I got it working on the Y axis using Comtois's formulae: I'm a bit concerned,though, when you need to load a mesh of unknown dimensions.
Okay..A little messy, but you'll get the point. The Y are placed correctly now, but...
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
DeclareModule _3D_Eggs
Structure Mesh_Data
ID.i
Mesh.i
Tex.i
Mat.i
EndStructure
Global CamSpeed = 10
Global MouseSpeed = 10
Global DefaultCam.i
Global Win.i, Light.i
Global earth.Mesh_Data
Global MotherEgg.Mesh_Data
Global NewList KidsEgg.Mesh_Data()
Declare SetupWinScreen(Width.i, Height.i, Title.s = "")
Declare MakeTestTerrain()
Declare MakeEggs()
Declare Do_Mouse()
Declare Do_Keyboard()
EndDeclareModule
Module _3D_Eggs
Procedure SetupWinScreen(Width.i, Height.i, Title.s = "") ; Setup screen, Get Dimensions, and set a default camera
winWidth = Width: winHeight = Height-5
Win = OpenWindow(#PB_Any, 0, 0, Width, Height, Title, #PB_Window_SystemMenu )
OpenWindowedScreen(WindowID(Win), 0, 0, Width, Height-5, 0, 0, 0,#PB_Screen_SmartSynchronization)
DefaultCam = CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(DefaultCam,0,100,150)
CameraProjectionMode(DefaultCam, #PB_Camera_Perspective)
light = CreateLight(#PB_Any ,RGB(190, 190, 190), 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))
EndProcedure
Procedure MakeTestTerrain()
earth\Mesh = CreatePlane(#PB_Any,100000,100000,2,2,1,1)
earth\Tex = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(earth\Tex))
Box(0,0,512,512,$FFFFFF)
StopDrawing()
earth\Mat = CreateMaterial(#PB_Any,TextureID(earth\Tex))
earth\ID = CreateEntity(#PB_Any,MeshID(earth\Mesh),MaterialID(earth\Mat))
MoveEntity(earth\ID,0,0,0,#PB_Absolute)
EndProcedure
Procedure MakeEggs()
MotherEgg\Mesh = CreateSphere(#PB_Any,50,20,20)
MotherEgg\Tex = CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(MotherEgg\Tex))
Box(0,0,256,256,$00FF00)
StopDrawing()
MotherEgg\Mat = CreateMaterial(#PB_Any,TextureID(MotherEgg\Tex))
MotherEgg\ID = CreateEntity(#PB_Any, MeshID(MotherEgg\Mesh), MaterialID(MotherEgg\Mat))
MoveEntity(MotherEgg\ID,0,0,0)
RenderWorld() ;Update
For x = 0 To 30
AddElement(KidsEgg())
KidsEgg()\ID = CopyEntity(MotherEgg\ID,#PB_Any)
ScaleEntity(KidsEgg()\ID,Random(10,5),Random(10,5),Random(10,5))
MoveEntity(KidsEgg()\ID, Random(20000,10), 0, Random(20000,10))
Next x
RenderWorld() ;update again, just in case
EndProcedure
Procedure Do_Mouse()
ExamineMouse()
MouseX = -MouseDeltaX() * MouseSpeed * 0.01
MouseY = -MouseDeltaY() * MouseSpeed * 0.01
RotateCamera(DefaultCam, MouseY, MouseX, 0, #PB_Relative)
EndProcedure
Procedure Do_Keyboard()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_A)
KeyX = 0 - CamSpeed
EndIf
If KeyboardPushed(#PB_Key_D)
KeyX = CamSpeed
EndIf
If KeyboardPushed(#PB_Key_W)
KeyY = 0 - CamSpeed
EndIf
If KeyboardPushed(#PB_Key_S)
KeyY = CamSpeed
EndIf
MoveCamera(DefaultCam, KeyX, 0, KeyY)
If Not KeyboardReleased(#PB_Key_Escape)
KeyX = 0: KeyY = 0
EndIf
EndProcedure
EndModule
_3D_Eggs::SetupWinScreen(1024,768)
_3D_Eggs::MakeTestTerrain()
_3D_Eggs::MakeEggs()
onlyonce = 0
Repeat
ev = WindowEvent()
elaps = RenderWorld()
If onlyonce = 0 ;Only run the test once
; Since I made the MotherEgg, I know that the size is 50, but what if I don't know the original size in advanced?
stdval = EntityBoundingBox(_3D_Eggs::MotherEgg\ID , #PB_Entity_MinBoundingBoxY | #PB_Entity_WorldBoundingBox) / EntityBoundingBox(_3D_Eggs::MotherEgg\ID , #PB_Entity_MinBoundingBoxY | #PB_Entity_LocalBoundingBox)
Debug "Org Y MotherEgg: " + stdval ; as espected..Value of 1
ForEach _3D_Eggs::KidsEgg()
newvalX = 0: newvalY = 0: newvalZ = 0
newvalX = EntityBoundingBox(_3D_Eggs::KidsEgg()\ID , #PB_Entity_MinBoundingBoxX | #PB_Entity_WorldBoundingBox) / EntityBoundingBox(_3D_Eggs::KidsEgg()\ID , #PB_Entity_MinBoundingBoxX | #PB_Entity_LocalBoundingBox)
newvalY = EntityBoundingBox(_3D_Eggs::KidsEgg()\ID , #PB_Entity_MinBoundingBoxY | #PB_Entity_WorldBoundingBox) / EntityBoundingBox(_3D_Eggs::KidsEgg()\ID , #PB_Entity_MinBoundingBoxY | #PB_Entity_LocalBoundingBox)
newvalZ = EntityBoundingBox(_3D_Eggs::KidsEgg()\ID , #PB_Entity_MinBoundingBoxZ | #PB_Entity_WorldBoundingBox) / EntityBoundingBox(_3D_Eggs::KidsEgg()\ID , #PB_Entity_MinBoundingBoxZ | #PB_Entity_LocalBoundingBox)
Debug " X : " + newvalX
Debug " Y : " + newvalY
Debug " Z : " + newvalZ
MoveEntity(_3D_Eggs::KidsEgg()\ID,Random(10000,10), 50 * newvalY, Random(10000,10)) ;Just crap locations
Next
onlyonce = 1
EndIf
_3D_Eggs::Do_Mouse()
_3D_Eggs::Do_Keyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
But for the life of me, I don't get the negative values on x and z.
Oh well.. I'm still learning bigtime and I'm sure Comtois 'the wizard' will provide enlightenment soon.