https://3dwarehouse.sketchup.com/model. ... c10dfa4b4d
using sketchUp to export it to *.3ds file then using the great OgreAssimpConverter http://www.purebasic.fr/english/viewtop ... 22#p401729 to convert it to Ogre *.mesh file
i have used the official purebasic example ThirdPerson.pb to replace the cubes with the stonehenge model. and a tiny other changes.
use the keys to move and rotate the robot , and the mouse to look up/down. press H to hide/unhide the Robot
the example ThirdPerson.pb can be used as a base for such tours with physics to virtual places such as museums, places etc.
how to run : download the code and the mesh with all textures from here:
http://www.2shared.com/file/icaehulb/stonehenge3.html
notes: the place to position the camera away or high from the robot is in line 173: \CameraNode = CreateNode(#PB_Any, -100, 100, 0)


Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - Third Person
;
; (c) 2011 - Fantaisie Software
;
; ------------------------------------------------------------
;
; edited by applePi to add the stonehenge model to it
IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
#PlayerSpeed = 60
#CameraSpeed = 10
Global.f MouseY = 50
Structure Vector3
x.f
y.f
z.f
EndStructure
Structure s_Key
Up.i
Down.i
Left.i
Right.i
StrafeLeft.i
StrafeRight.i
Jump.i
EndStructure
Structure s_Entity
Entity.i
EntityBody.i
BodyOffsetY.f
elapsedTime.f
Key.s_Key
MainNode.i
SightNode.i
CameraNode.i
ForwardNode.i
StrafeNode.i
EndStructure
Structure s_Camera
Camera.i
Tightness.f
CameraNode.i
TargetNode.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)
Declare CameraTrack(*Camera.s_Camera, *Entity.s_Entity)
Declare OnGround(*Entity.s_Entity)
Define Robot.s_Entity
Define Camera.s_Camera
Define.f TimeSinceLastFrame = 0
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
;Add3DArchive("../Data/Textures" , #PB_3DArchive_FileSystem)
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)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/GUI" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive("." , #PB_3DArchive_FileSystem)
Parse3DScripts()
WorldShadows(#PB_Shadow_Modulative, 3000, RGB(150, 150, 150))
;WorldShadows(#PB_Shadow_Additive,3000, RGB(150, 150, 150))
;Texture
CreateTexture(1, 256, 256)
StartDrawing(TextureOutput(1))
Box(0, 0, 256, 256, RGB(138, 115, 38))
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, 256, 256, RGB(255, 255, 0))
Box(10, 10, 236, 236, RGB(255, 255, 50))
StopDrawing()
;Material
CreateMaterial(0, LoadTexture(0, "r2skin.jpg"))
CreateMaterial(1, TextureID(1))
MaterialFilteringMode(1, 2)
CreateMaterial(2, LoadTexture(2, "Dirt.jpg"))
CreateMaterial(3, LoadTexture(3, "Wood.jpg"))
GetScriptMaterial(4, "Scene/GroundBlend")
MaterialFilteringMode(1, #PB_Material_Anisotropic, 8)
;Robot
LoadMesh (0, "robot.mesh")
CreateEntity (0, MeshID(0), #PB_Material_None);
StartEntityAnimation(0, "Walk")
HideEntity(0, 1)
;Robot Body
CreateEntity(1, MeshID(0), #PB_Material_None, -100, 126, -500)
RotateEntity(1, 0,-60,0)
HideEntity(1, 1)
;Ground
CreatePlane(2, 5000, 5000, 100, 100, 100, 100)
CreateEntity(2, MeshID(2), MaterialID(1), 0, 0, 0)
;Body
EntityPhysicBody(1, #PB_Entity_CapsuleBody, 1, 0, 0)
EntityPhysicBody(2, #PB_Entity_StaticBody)
;-Light
;CreateLight(0,RGB(255,255,155),700,500,0)
;AmbientColor(RGB(255,255,255))
CreateLight(1,RGB(200,248,13),1000,700,1600, #PB_Light_Point )
AmbientColor(RGB(255,255,255))
;- Fog
Fog(RGB(210, 210, 210), 1, 0, 10000)
; Skybox
SkyBox("desert07.jpg")
; stonehenge
LoadMesh(20, "stonehenge3_03ds.mesh")
NormalizeMesh(20)
BuildMeshShadowVolume(20)
BuildMeshTangents(20)
CreateEntity(20,MeshID(20), #PB_Material_None,1000,-70,1600)
ScaleEntity(20,2000,2000,2000)
EntityPhysicBody(20, #PB_Entity_StaticBody )
EntityRenderMode(20, #PB_Entity_CastShadow )
;MoveEntity(1, 1000, 1000, 2000)
;
With Robot
\Entity = 0
\EntityBody = 1
\BodyOffsetY = 43
\Key\Down = #PB_Key_Down
\Key\Left = #PB_Key_Left
\Key\Right = #PB_Key_Right
\Key\Up = #PB_Key_Up
\Key\StrafeLeft = #PB_Key_X
\Key\StrafeRight = #PB_Key_C
\Key\Jump = #PB_Key_Space
\MainNode = CreateNode(#PB_Any) ; Entity position
\SightNode = CreateNode(#PB_Any, 120, 50, 0) ; For cameraLookAt
;\CameraNode = CreateNode(#PB_Any, -340, 100, 0) ; Camera position
\CameraNode = CreateNode(#PB_Any, -100, 100, 0) ; Camera position
\ForwardNode = CreateNode(#PB_Any, 1, 0, 0) ; Direction normalized
\StrafeNode = CreateNode(#PB_Any, 0, 0, -1) ; Direction normalized
AttachNodeObject(\MainNode, NodeID(\SightNode))
AttachNodeObject(\MainNode, NodeID(\CameraNode))
AttachNodeObject(\MainNode, NodeID(\ForwardNode))
AttachNodeObject(\MainNode, NodeID(\StrafeNode))
AttachNodeObject(\MainNode, EntityID(\Entity))
EndWith
;-Camera
CreateCamera(0, 0, 0, 100, 100)
With Camera
\Camera = 0
\Tightness = 0.035
; Camera use 2 nodes
\CameraNode = CreateNode(#PB_Any, -3000, 700, 0) ; Camera position
\TargetNode = CreateNode(#PB_Any) ; For cameraLookAt
AttachNodeObject(\CameraNode, CameraID(\Camera))
EndWith
;-Main loop
;
Repeat
Screen3DEvents()
Robot\elapsedTime = TimeSinceLastFrame * 40
HandleEntity(@Robot)
CameraTrack(@Camera, @Robot)
If KeyboardReleased(#PB_Key_H)
HideEntity(0,hide)
hide ! 1
EndIf
TimeSinceLastFrame = RenderWorld(50) / 1000
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Procedure OnGround(*Entity.s_Entity)
With *Entity
ProcedureReturn RayCollide(NodeX(\MainNode), NodeY(\MainNode)+3, NodeZ(\MainNode), NodeX(\MainNode), NodeY(\MainNode), NodeZ(\MainNode))
EndWith
EndProcedure
Procedure HandleEntity(*Entity.s_Entity)
Protected.Vector3 Forward, Strafe, PosMain, PosDir, PosStrafe
Protected.f Speed, Speed2, x, y, MouseX
Static Jump.f, MemJump.i, Rot.Vector3, Trans.Vector3, Clic, MouseY
With *Entity
GetNodePosition(PosMain, \MainNode)
GetNodePosition(PosDir, \ForwardNode)
GetNodePosition(PosStrafe, \StrafeNode)
SubVector3(Forward, PosDir, PosMain)
SubVector3(Strafe, PosStrafe, PosMain)
Speed = #PlayerSpeed * \elapsedTime
Speed2 = Speed / 2
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F5)
WorldDebug(#PB_World_DebugBody)
ElseIf KeyboardReleased(#PB_Key_F6)
WorldDebug(#PB_World_DebugEntity)
ElseIf KeyboardReleased(#PB_Key_F7)
WorldDebug(#PB_World_DebugNone)
EndIf
If KeyboardPushed(\Key\Jump) And OnGround(*Entity)>-1
Jump = 4
MemJump = 1
EndIf
Rot\x * 0.30
Rot\y * 0.30
Rot\z * 0.30
Trans\x * 0.20
Trans\y = Jump
Trans\z * 0.20
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)
Rot\y + 2 * \elapsedTime
ElseIf KeyboardPushed(\Key\Right)
Rot\y - 2 * \elapsedTime
EndIf
If KeyboardPushed(\Key\StrafeLeft)
Trans\x + Strafe\x * Speed2
Trans\z + Strafe\z * Speed2
ElseIf KeyboardPushed(\Key\StrafeRight)
Trans\x + Strafe\x * -Speed2
Trans\z + Strafe\z * -Speed2
EndIf
If OnGround(*Entity) > -1
Jump = 0
ElseIf MemJump
Jump + 20
If Jump > 80
MemJump = 0
EndIf
Else
Jump - 9
EndIf
EndIf
MoveEntity (\EntityBody, Trans\x, Trans\y, Trans\z)
RotateEntity(\EntityBody, 0, Rot\y, 0, #PB_Relative)
MoveNode(\MainNode, EntityX(\EntityBody), EntityY(\EntityBody)-\BodyOffsetY, EntityZ(\EntityBody), #PB_Absolute)
RotateNode(\MainNode, 0, EntityYaw(\EntityBody), 0)
EndWith
EndProcedure
Procedure CameraTrack(*Camera.s_Camera, *Entity.s_Entity)
Protected.Vector3 CameraPosition, TargetPosition
Protected.f x, y, z
GetNodePosition(CameraPosition, *Entity\CameraNode)
GetNodePosition(TargetPosition, *Entity\SightNode)
x = NodeX(*Camera\CameraNode)
y = NodeY(*Camera\CameraNode)
z = NodeZ(*Camera\CameraNode)
x = (CameraPosition\x - x) * *Camera\Tightness
y = (CameraPosition\y - y) * *Camera\Tightness
z = (CameraPosition\z - z) * *Camera\Tightness
MoveNode(*Camera\CameraNode, x, y, z)
x = NodeX(*Camera\TargetNode)
y = NodeY(*Camera\TargetNode)
z = NodeZ(*Camera\TargetNode)
x = (TargetPosition\x - x) * *Camera\Tightness
y = (TargetPosition\y - y) * *Camera\Tightness
z = (TargetPosition\z - z) * *Camera\Tightness
MoveNode(*Camera\TargetNode, x, y, z)
If ExamineMouse()
MouseY = MouseY - MouseDeltaY() * 1
EndIf
CameraLookAt(*Camera\Camera, NodeX(*Camera\TargetNode)+ MouseX, NodeY(*Camera\TargetNode)+MouseY, NodeZ(*Camera\TargetNode))
EndProcedure