Psychophanta, I know from long time ago that #PB_World, #PB_Local, #PB_Parent is useless, this is why i use always #PB_Absolute, #PB_Relative only.
nothing better than a solar system to demonstrate these things. in my second example above the planets is attached to the cone and they rotate around it with MoveEntity using #PB_Absolute. and then we do MoveEntity the Cone using #PB_Absolute in a Big orbit, and it works, a solar system .
but we can say how it works the absolute of the absolute: #PB_Absolute of the cone X (#PB_Absolute of the planets) ! i realize the dilemma, surely a matrix mathematics is playing behind the scene here.
here is even more complex i have added a cube. and the cone is attached to the cube, the spheres is attached to the cone. when we rotate the cube with moveEntity (#PB_Absolute) now the cone (and its planets) is rotating around the cube... .
but i can't rotate the cube (the big Master) around itself without affecting all the system . in this case i have to attach a fake CubeWife to the Cube in the cube position, and then rotate the CubeWife while hiding the Cube with HideEntity(). the CubeWife should be at the same position as the Cube by the pure action of attachment or
, it does not work to move it Globally since it stay at a fixed distance from the cube (here i see a Bug crawling from the complexity, and we need a working #PB_World, #PB_Local, #PB_Parent)
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 800, 600, " scene ... press Space to toggle Camera Position", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateCamera(0, 0, 0, 100, 100)
;MoveCamera(0, 0, 5, 25)
MoveCamera(0, 0, 45, 0.0001, #PB_Absolute)
CameraLookAt(0, 0,0,0)
CameraBackColor(0, RGB(155,155,155))
GreenMaterial = GetScriptMaterial(#PB_Any, "Color/Yellow")
RedMaterial = GetScriptMaterial(#PB_Any, "Color/Green")
CarTexture = LoadTexture(#PB_Any, "RustyBarrel.png")
CarMaterial = CreateMaterial(#PB_Any, TextureID(CarTexture))
SetMaterialColor(CarMaterial, #PB_Material_SelfIlluminationColor, RGB(0,0,255))
SetMaterialColor(RedMaterial, #PB_Material_SelfIlluminationColor, RGB(200,0,25))
CreateMaterial(1, LoadTexture(1, "Dirt.jpg"))
CreateMaterial(4, LoadTexture(4, "RustyBarrel.png"))
;CreateLight(#Light, Color [, x, y, z [, Flags]])
;CreateLight(1, RGB(220,20,120), 0,100,20)
CreateLight(1, RGB(220,220,220), 0,100,20)
;CreateLight(2, RGB(220,220,220), -100,100,-10)
ConeMesh = CreateCone(#PB_Any, 0.6, 1, 16, 8)
SphereMesh = CreateSphere(#PB_Any,0.5)
carMesh = LoadMesh(#PB_Any, "chassis.mesh")
CubeMesh = CreateCube(#PB_Any, 1)
SetMeshMaterial(ConeMesh, MaterialID(RedMaterial))
SetMeshMaterial(CubeMesh, MaterialID(RedMaterial))
Cone = CreateEntity(#PB_Any, MeshID(ConeMesh), #PB_Material_None, 0, 0, 0)
Cube = CreateEntity(#PB_Any, MeshID(CubeMesh), #PB_Material_None, 0, 0, 0)
CubeWife = CreateEntity(#PB_Any, MeshID(CubeMesh), #PB_Material_None, 0, 0, 0)
Sphere1 = CreateEntity(#PB_Any, MeshID(SphereMesh), MaterialID(GreenMaterial), -5, 0, 0)
Sphere2 = CreateEntity(#PB_Any, MeshID(SphereMesh), MaterialID(GreenMaterial), 5, 0, 0)
sphere3 = CreateEntity(#PB_Any, MeshID(SphereMesh), MaterialID(GreenMaterial), 0, 0, 5)
sphere4 = CreateEntity(#PB_Any, MeshID(SphereMesh), MaterialID(GreenMaterial), 0, 0, -5)
Car = CreateEntity(#PB_Any, MeshID(CarMesh), MaterialID(CarMaterial), 0, 1, 0)
ScaleEntity(car, 0.4,0.4,0.4)
AttachEntityObject(Cone, "", EntityID(sphere1));, 10, -8, -5, 0, 0, 0)
AttachEntityObject(Cone, "", EntityID(sphere2))
AttachEntityObject(Cone, "", EntityID(sphere3))
AttachEntityObject(Cone, "", EntityID(sphere4))
AttachEntityObject(Cone, "", EntityID(Car))
AttachEntityObject(Cube, "", EntityID(Cone))
AttachEntityObject(Cube, "", EntityID(CubeWife))
;create ground entity using the Cone mesh number 0 created above
ground = CreateEntity(#PB_Any, MeshID(ConeMesh), #PB_Material_None, 0, -2, 0)
; and then we scale it to resemble a ground
ScaleEntity(ground, 12,0.5,12)
CreateCapsule(5, 0.2,1)
CreateEntity(5, MeshID(5), MaterialID(4), -3,-1,0)
CreateSphere(6, 1)
CreateEntity(6, MeshID(6), MaterialID(1), -3,-0.3,0)
ScaleEntity(6,1,0.1,1)
OrbitRadius.f = 2.5
angle1.f = 0
angle2.f = 2*#PI/4
angle3.f = 2*#PI/2
angle4.f = 2*#PI*3/4
angle0.f = 0
flag = 1
Repeat
Repeat
event = WindowEvent()
Until event = 0
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space)
If flag
;MoveCamera(0, 0, 45, 0.0001, #PB_Absolute)
MoveCamera(0, 0, 10, 35, #PB_Absolute)
CameraLookAt(0, 0,0,0)
flag ! 1
Else
;MoveCamera(0, 0, 5, 35, #PB_Absolute)
MoveCamera(0, 0, 45, 0.0001, #PB_Absolute)
CameraLookAt(0, 0,0,0)
flag ! 1
EndIf
EndIf
angle1.f - 0.05
angle2.f - 0.05
angle3.f - 0.05
angle4.f - 0.05
x1.f=Cos(angle1)*OrbitRadius
z1.f=Sin(angle1)*OrbitRadius
x2.f=Cos(angle2)*OrbitRadius
z2.f=Sin(angle2)*OrbitRadius
x3.f=Cos(angle3)*OrbitRadius
z3.f=Sin(angle3)*OrbitRadius
x4.f=Cos(angle4)*OrbitRadius
z4.f=Sin(angle4)*OrbitRadius
MoveEntity(sphere1, x1,2,z1, #PB_Absolute )
MoveEntity(sphere2, x2,2, z2, #PB_Absolute )
MoveEntity(sphere3, x3,2, z3, #PB_Absolute )
MoveEntity(sphere4, x4,2, z4, #PB_Absolute )
;RotateEntity(Cone, 0,1,0, #PB_Relative) ; rotate the parent
angle0.f + 0.01
x0.f=Cos(angle0)*OrbitRadius*2
z0.f=Sin(angle0)*OrbitRadius*2
MoveEntity(Cone, x0,2, z0, #PB_Absolute)
angle5.f + 0.002
x5.f=Cos(angle5)*OrbitRadius * 4
z5.f=Sin(angle5)*OrbitRadius * 4
MoveEntity(Cube, x5,2, z5, #PB_Absolute)
;MoveEntity(CubeWife, x5,2, z5, #PB_Absolute) ;does Not work
;MoveEntity(CubeWife, 0,2, 0, #PB_Absolute) ; works okay
RotateEntity(CubeWife, 0,5,0, #PB_Relative)
HideEntity(Cube, 1) ; to prevent the flicker
RenderWorld()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)