before a few months i need to make a room textured with stars, and i need to move inside the room which have a table and a football, and when you enter the room door the football fall down and a music alarm , so i have used the FPSFirstPerson.pb example, but even i don't understand how it works because it is a mathematics and geometry problem (vectors ...etc) , and i want only to focus on my specific roaming inside the room issue, so the following is an example of utilizing a complex example without knowing how it works, the example have physics and you can't go inside the room but only from its door. open the computer speakers
PS: i can't download your code, i have used opera and then google chrome and i have signed in but i can't download it
the camera here are inside the eyes of the robot, but if you want the robot to be at specific distance, i need more time to study the original FPSFirstPerson.pb since my program are several months ago
Code: Select all
#PlayerSpeed = 200
#CameraSpeed = 14
Global collision
Global joint = 66
Enumeration
#tex = 100
#mat
#BillboardGroup
#Billboard
#table
#leg1
#leg2
#leg3
#leg4
#tableMaterial
#football
#camera
#cameraBody ; the robot
EndEnumeration
Structure Vector3
x.f
y.f
z.f
EndStructure
Structure s_Key
Up.i
Down.i
Left.i
Right.i
Jump.i
EndStructure
Structure s_Entity
EntityBody.i
BodyOffsetY.f
elapsedTime.f
Fov.f
Key.s_Key
MainNode.i
CameraNode.i
HandNode.i
ForwardNode.i
StrafeNode.i
EndStructure
Macro GetNodePosition(Position, Node)
Position\x = NodeX(Node)
Position\y = NodeY(Node)
Position\z = NodeZ(Node)
EndMacro
Macro SubVector3(V, V1, V2)
V\x = V1\x - V2\x
V\y = V1\y - V2\y
V\z = V1\z - V2\z
EndMacro
;-Declare
Declare HandleEntity(*Entity.s_Entity)
Define Robot.s_Entity
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
ExamineDesktops()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
DeskWidth=DesktopWidth(0)
DeskHeight=DesktopHeight(0)
If LoadFont(0, "Arial", 30,#PB_Font_Bold)
SetGadgetFont(#PB_Default, FontID(0))
EndIf
OpenWindow(0, 0, 0, DeskWidth, DeskHeight, "Room _ press space to fly, arrows to move, mouse to rotate ", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, DeskWidth, DeskHeight, 0, 0, 0)
LoadSound(collision,"britneyspears3.wav")
LoadMesh(0, "room_obj.mesh")
CreateEntity(0,MeshID(0), #PB_Material_None,0,-35,0)
RotateEntity(0, 0,-17,0)
ScaleEntity(0,16000,11000,16000)
;ScaleEntity(0,35000,20000,35000)
EntityPhysicBody(0, #PB_Entity_StaticBody )
CreateSphere(#football, 50)
CreateMaterial(34, LoadTexture(34, "football.jpg"))
CreateEntity(#football,MeshID(#football), MaterialID(34),0,1000,0)
EntityPhysicBody(#football, #PB_Entity_SphereBody , 5,2,3)
PointJoint(joint, EntityID(#football), 0, 10, 0 , EntityID(0), 0, 1000, 0)
;plane textured with squares
CreateMaterial(3, LoadTexture(3, "MRAMOR6X6.jpg"))
MaterialCullingMode(3, #PB_Material_NoCulling )
CreatePlane(1,7000,7000,1,1,8,8)
CreateEntity(1,MeshID(1),MaterialID(3),0,0,0)
EntityPhysicBody(1, #PB_Entity_StaticBody,1,0.3,1)
; Camera
CreateCamera(#camera, 0, 0, 100, 100)
CameraBackColor(#camera, RGB(177,191,245))
;MoveCamera(0,0, 100, 300,#PB_Absolute)
;MoveCamera(#camera,-226.81, 334.93, 3474.49,#PB_Absolute)
;MoveCamera(#camera,-226.81, 334.93, 0,#PB_Absolute)
CameraLookAt(#camera, 0, 0, 0)
; Light
CreateLight(0, RGB(230,230,230), 0, 2000, 0) ; general light
SetLightColor(0, #PB_Light_SpecularColor, RGB(255,255,255))
CreateLight(1, RGB(230,230,230), 0, 200, 0) ; light in the position of the sprite
SetLightColor(1, #PB_Light_SpecularColor, RGB(255,255,255))
WorldShadows(#PB_Shadow_Additive , 6000, RGB(200,200,200))
LoadTexture(#tex , "Lensflare5.jpg") ; for the sprite
CreateMaterial(#mat, TextureID(#tex))
SetMaterialColor(#mat, #PB_Material_AmbientColor, RGB(1,1,1))
SetMaterialColor(#mat, #PB_Material_DiffuseColor, RGB(1,1,1))
DisableMaterialLighting(#mat, 1)
MaterialBlendingMode(#mat, #PB_Material_Add )
MaterialDepthWrite(#mat, Disable)
CreateBillboardGroup(#BillboardGroup, MaterialID(#mat), 100,100, 0, 0, 0)
AddBillboard(#Billboard, #BillboardGroup, 0, 200, 0)
; table and its 4 Legs
CreateMaterial(#tableMaterial, LoadTexture(#tex , "Wood.jpg"))
CreateCube(#table, 10)
CreateEntity(#table,MeshID(#table), MaterialID(#tableMaterial),0,35,0)
EntityPhysicBody(#table, #PB_Entity_ConvexHullBody , 100,1,1)
ScaleEntity(#table,10,1,20)
CopyEntity(#table, #leg1)
ScaleEntity(#leg1, 0.3,1,0.05)
RotateEntity(#leg1, 0,0,90)
MoveEntity(#leg1, 40, 16,90)
EntityPhysicBody(#leg1, #PB_Entity_ConvexHullBody , 4,0,100)
CopyEntity(#leg1, #leg2)
RotateEntity(#leg2, 0,0,90)
MoveEntity(#leg2, -40, 16,90)
EntityPhysicBody(#leg2, #PB_Entity_ConvexHullBody , 4,0,100)
CopyEntity(#leg1, #leg3)
RotateEntity(#leg3, 0,0,90)
MoveEntity(#leg3, -40, 16,-90)
EntityPhysicBody(#leg3, #PB_Entity_ConvexHullBody , 4,0,100)
CopyEntity(#leg1, #leg4)
RotateEntity(#leg4, 0,0,90)
MoveEntity(#leg4, 40, 16,-90)
EntityPhysicBody(#leg4, #PB_Entity_ConvexHullBody , 4,0,100)
;- Robot Body
LoadMesh (#cameraBody, "robot.mesh")
CreateEntity(#cameraBody, MeshID(#cameraBody), #PB_Material_None, -227, 335, 3474)
EntityPhysicBody(#cameraBody, #PB_Entity_ConvexHullBody , 0.45, 0, 0) ; robot
With Robot
\Fov = 50
\EntityBody = #cameraBody
\BodyOffsetY = 43
\Key\Down = #PB_Key_Down ;Down
\Key\Left = #PB_Key_Left ;Left
\Key\Right = #PB_Key_Right;Right
\Key\Up = #PB_Key_Up ;Up
\Key\Jump = #PB_Key_Space
\MainNode = CreateNode(#PB_Any) ; Entity position
\CameraNode = CreateNode(#PB_Any, 0, 140, 50) ; Camera position
\HandNode = CreateNode(#PB_Any, 0, 80, 0) ; Hand position
\ForwardNode= CreateNode(#PB_Any, 0, 0, -1) ; Direction normalized
\StrafeNode = CreateNode(#PB_Any, -1, 0, 0) ; Direction normalized
AttachNodeObject(\MainNode , NodeID(\CameraNode))
AttachNodeObject(\MainNode , NodeID(\HandNode))
AttachNodeObject(\MainNode , NodeID(\ForwardNode))
AttachNodeObject(\MainNode , NodeID(\StrafeNode))
;RotateNode(\HandNode, 5, 0, 0, #PB_Relative)
EndWith
; Camera
CreateCamera(#camera, 0, 0, 100, 100)
CameraBackColor(#camera, RGB(177,191,245))
CameraRange(#camera, 0.08, 5000)
AttachNodeObject(Robot\CameraNode, CameraID(#camera))
CameraLookAt(#camera, NodeX(Robot\ForwardNode) * 100, NodeY(Robot\CameraNode), NodeZ(Robot\ForwardNode) * 100)
;WorldDebug(#PB_World_DebugBody)
HideEntity(#cameraBody, 1)
Repeat
;Screen3DEvents()
If Engine3DFrameRate(#PB_Engine3D_Current)
Robot\elapsedTime = 40/Engine3DFrameRate(#PB_Engine3D_Current)
;Robot\elapsedTime = 40/75
EndIf
HandleEntity(@Robot)
RenderWorld(60)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
FreeSound(collision)
End
Procedure HandleEntity(*Entity.s_Entity)
Protected.Vector3 Forward, Strafe, PosMain, PosDir, PosStrafe
Protected.f Speed, Speed2, SpeedShoot, x, y
Protected.f MouseX, MouseY
Static Jump.f, MemJump.i, Rot.Vector3, Trans.Vector3, Clic
With *Entity
GetNodePosition(PosMain, \MainNode)
GetNodePosition(PosDir, \ForwardNode)
GetNodePosition(PosStrafe, \StrafeNode)
SubVector3(Forward, PosDir, PosMain)
SubVector3(Strafe, PosStrafe, PosMain)
Speed = #PlayerSpeed * \elapsedTime
Speed2 = Speed * 0.5
SpeedShoot = Speed * 10
If ExamineMouse()
MouseX = -(MouseDeltaX()/200) * \Fov * \elapsedTime
MouseY = -(MouseDeltaY()/200) * \Fov * \elapsedTime
Rot\z = 0
Rot\y + MouseX
If NodePitch(\CameraNode) < 80 And MouseY > 0
Rot\x + MouseY
ElseIf NodePitch(\CameraNode) > -80 And MouseY < 0
Rot\x + MouseY
EndIf
If MouseButton(#PB_MouseButton_Right)
If \Fov > 20
\Fov - 2 * \elapsedTime
EndIf
Else
If \Fov < 50
\Fov + 2 * \elapsedTime
EndIf
EndIf
EndIf
If ExamineKeyboard()
If KeyboardPushed(\Key\Jump); And OnGround(*Entity)
Jump = 30
MemJump = 1
EndIf
Rot\x * 0.30
Rot\y * 0.30
Rot\z * 0.30
Trans\x * 0.80
Trans\y = Jump
Trans\z * 0.80
If KeyboardPushed(\Key\Up)
Trans\x = Forward\x * Speed
Trans\z = Forward\z * Speed
ElseIf KeyboardPushed(\Key\Down)
Trans\x = Forward\x * -Speed2
Trans\z = Forward\z * -Speed2
EndIf
If KeyboardPushed(\Key\Left)
Trans\x = Strafe\x * Speed
Trans\z = Strafe\z * Speed
ElseIf KeyboardPushed(\Key\Right)
Trans\x = Strafe\x * -Speed
Trans\z = Strafe\z * -Speed
EndIf
MoveEntity(\EntityBody, Trans\x, Trans\y, Trans\z)
re = RayCollide(-406, 0.35, 1603, 324, 0.35, 1555)
If re > 0
PlaySound(collision)
FreeJoint(joint)
ApplyEntityImpulse(#football, 0, -10, 0, 0,0,0)
EndIf
EndIf
If KeyboardReleased(#PB_Key_Z) ; for knowledge of position only and not necessary
Debug EntityX(\EntityBody)
Debug EntityY(\EntityBody)
Debug EntityZ(\EntityBody)
EndIf
Jump=-100
CameraFOV(#camera, \Fov)
RotateEntity(\EntityBody, 0, Rot\y, 0, #PB_Relative)
RotateNode(\CameraNode , Rot\x, 0, 0, #PB_Relative)
RotateNode(\HandNode , Rot\x, 0, 0, #PB_Relative)
MoveNode(\MainNode, EntityX(\EntityBody), EntityY(\EntityBody) - \BodyOffsetY, EntityZ(\EntityBody), #PB_Absolute)
RotateNode(\MainNode, 0, EntityYaw(\EntityBody), 0)
EndWith
EndProcedure