OSDN Git Service

Updated collision detection control, added gravity control
authorryan <>
Thu, 4 Dec 2008 01:51:33 +0000 (01:51 +0000)
committerryan <>
Thu, 4 Dec 2008 01:51:33 +0000 (01:51 +0000)
codeblocks/wxsmith/DebugPanel.wxs
src/camera.cpp
src/camera.h
src/debugpanel.cpp
src/debugpanel.h
src/sbs.cpp
src/sbs.h

index 20b8df2..3a850b5 100755 (executable)
@@ -67,7 +67,7 @@
                                                                        <object class="sizeritem">
                                                                                <object class="wxStaticText" name="ID_t_camerafloor" variable="t_camerafloor" member="yes">
                                                                                        <label></label>
-                                                                                       <size>100,-1</size>
+                                                                                       <size>150,-1</size>
                                                                                        <style>wxST_NO_AUTORESIZE</style>
                                                                                </object>
                                                                                <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
@@ -76,7 +76,7 @@
                                                                        <object class="sizeritem">
                                                                                <object class="wxStaticText" name="ID_t_camerap" variable="t_camerap" member="yes">
                                                                                        <label></label>
-                                                                                       <size>100,-1</size>
+                                                                                       <size>150,-1</size>
                                                                                        <style>wxST_NO_AUTORESIZE</style>
                                                                                </object>
                                                                                <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
@@ -85,7 +85,7 @@
                                                                        <object class="sizeritem">
                                                                                <object class="wxStaticText" name="ID_t_elevnumber" variable="t_elevnumber" member="yes">
                                                                                        <label></label>
-                                                                                       <size>100,-1</size>
+                                                                                       <size>150,-1</size>
                                                                                        <style>wxST_NO_AUTORESIZE</style>
                                                                                </object>
                                                                                <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
@@ -94,7 +94,7 @@
                                                                        <object class="sizeritem">
                                                                                <object class="wxStaticText" name="ID_t_elevfloor" variable="t_elevfloor" member="yes">
                                                                                        <label></label>
-                                                                                       <size>100,-1</size>
+                                                                                       <size>150,-1</size>
                                                                                        <style>wxST_NO_AUTORESIZE</style>
                                                                                </object>
                                                                                <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
                                                                        <object class="sizeritem">
                                                                                <object class="wxStaticText" name="ID_t_object" variable="t_object" member="yes">
                                                                                        <label></label>
-                                                                                       <size>100,-1</size>
+                                                                                       <size>150,-1</size>
                                                                                        <style>wxST_NO_AUTORESIZE</style>
                                                                                </object>
-                                                                               <flag>wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+                                                                               <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+                                                                               <border>5</border>
                                                                        </object>
                                                                        <object class="sizeritem">
                                                                                <object class="wxStaticText" name="ID_STATICTEXT7" variable="t_framerate" member="yes">
                                                                                        <label></label>
-                                                                                       <size>100,-1</size>
+                                                                                       <size>150,-1</size>
                                                                                        <style>wxST_NO_AUTORESIZE</style>
                                                                                </object>
-                                                                               <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
+                                                                               <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
                                                                                <border>5</border>
                                                                                <option>1</option>
                                                                        </object>
                                                                </object>
-                                                               <flag>wxALL|wxALIGN_RIGHT|wxALIGN_TOP</flag>
+                                                               <flag>wxALIGN_RIGHT|wxALIGN_TOP</flag>
+                                                               <border>5</border>
                                                        </object>
                                                </object>
                                                <flag>wxRIGHT|wxALIGN_LEFT|wxALIGN_TOP</flag>
                                                                <border>5</border>
                                                        </object>
                                                        <object class="sizeritem">
+                                                               <object class="wxCheckBox" name="ID_chkGravity" variable="chkGravity" member="yes">
+                                                                       <label>Gravity</label>
+                                                                       <handler function="On_chkGravity_Click" entry="EVT_CHECKBOX" />
+                                                               </object>
+                                                               <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+                                                               <border>5</border>
+                                                               <option>1</option>
+                                                       </object>
+                                                       <object class="sizeritem">
                                                                <object class="wxCheckBox" name="ID_chkFrameLimiter" variable="chkFrameLimiter" member="yes">
                                                                        <label>Frame Limiter</label>
                                                                        <handler function="On_chkFrameLimiter_Click" entry="EVT_CHECKBOX" />
                                                                        <label>Framerate Sync</label>
                                                                        <handler function="On_chkFrameSync_Click" entry="EVT_CHECKBOX" />
                                                                </object>
-                                                               <flag>wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+                                                               <flag>wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+                                                               <border>5</border>
                                                        </object>
                                                </object>
                                                <flag>wxALL|wxALIGN_RIGHT|wxALIGN_TOP</flag>
index c7969ff..9296570 100644 (file)
@@ -68,6 +68,9 @@ Camera::Camera()
        cfg_legs_width = 1.312f;
        cfg_legs_depth = 1.312f;
        speed = 1;
+       EnableCollisions = true;
+       GravityStatus = true;
+       SetGravity(sbs->MetersToFeet(9.806)); // 9.806 m/s/s
 }
 
 Camera::~Camera()
@@ -119,7 +122,7 @@ void Camera::UpdateCameraFloor()
 bool Camera::Move(csVector3 vector, float speed)
 {
        //moves the camera in a relative amount specified by a vector
-       MainCamera->Move(vector * speed, sbs->EnableCollisions);
+       MainCamera->Move(vector * speed, EnableCollisions);
        return true;
 }
 
@@ -392,7 +395,7 @@ void Camera::CreateColliders()
 void Camera::Loop()
 {
        //set collision detection status
-       collider_actor.SetCD(sbs->EnableCollisions);
+       collider_actor.SetCD(EnableCollisions);
 
        //calculate acceleration
        InterpolateMovement();
@@ -477,10 +480,25 @@ void Camera::InterpolateMovement()
 
 void Camera::SetGravity(float gravity)
 {
-       collider_actor.SetGravity(gravity);
+       Gravity = gravity;
+       collider_actor.SetGravity(Gravity);
 }
 
 float Camera::GetGravity()
 {
-       return collider_actor.GetGravity();
+       return Gravity;
+}
+
+void Camera::EnableGravity(bool value)
+{
+       if (value == true)
+               collider_actor.SetGravity(Gravity);
+       else
+               collider_actor.SetGravity(0.0f);
+       GravityStatus = value;
+}
+
+bool Camera::GetGravityStatus()
+{
+       return GravityStatus;
 }
index 518dd01..fb30a59 100644 (file)
@@ -56,6 +56,7 @@ public:
        csVector3 desired_angle_velocity;
        csVector3 angle_velocity;
        float speed; //movement speed base
+       bool EnableCollisions; //enable collision detection
 
        //functions
        Camera();
@@ -93,6 +94,8 @@ public:
        void InterpolateMovement();
        void SetGravity(float gravity);
        float GetGravity();
+       void EnableGravity(bool value);
+       bool GetGravityStatus();
 
 private:
        csRef<iCamera> MainCamera; //main first-person view camera
@@ -103,6 +106,8 @@ private:
        char intbuffer[65];
        char buffer[20];
        int FloorTemp; //previous floor check value
+       float Gravity;
+       bool GravityStatus;
 
        //collision
        csColliderActor collider_actor;
index 0f3c6f8..b2ca55b 100644 (file)
@@ -56,6 +56,7 @@ const long DebugPanel::ID_t_object = wxNewId();
 const long DebugPanel::ID_STATICTEXT7 = wxNewId();
 const long DebugPanel::ID_STATICTEXT11 = wxNewId();
 const long DebugPanel::ID_chkCollisionDetection = wxNewId();
+const long DebugPanel::ID_chkGravity = wxNewId();
 const long DebugPanel::ID_chkFrameLimiter = wxNewId();
 const long DebugPanel::ID_chkMainProcessing = wxNewId();
 const long DebugPanel::ID_chkAutoShafts = wxNewId();
@@ -94,19 +95,19 @@ DebugPanel::DebugPanel(wxWindow* parent,wxWindowID id)
        BoxSizer6->Add(StaticText6, 1, wxBOTTOM|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
        BoxSizer4->Add(BoxSizer6, 0, wxRIGHT|wxALIGN_LEFT|wxALIGN_TOP, 5);
        BoxSizer7 = new wxBoxSizer(wxVERTICAL);
-       t_camerafloor = new wxStaticText(this, ID_t_camerafloor, wxEmptyString, wxDefaultPosition, wxSize(100,-1), wxST_NO_AUTORESIZE, _T("ID_t_camerafloor"));
+       t_camerafloor = new wxStaticText(this, ID_t_camerafloor, wxEmptyString, wxDefaultPosition, wxSize(150,-1), wxST_NO_AUTORESIZE, _T("ID_t_camerafloor"));
        BoxSizer7->Add(t_camerafloor, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
-       t_camerap = new wxStaticText(this, ID_t_camerap, wxEmptyString, wxDefaultPosition, wxSize(100,-1), wxST_NO_AUTORESIZE, _T("ID_t_camerap"));
+       t_camerap = new wxStaticText(this, ID_t_camerap, wxEmptyString, wxDefaultPosition, wxSize(150,-1), wxST_NO_AUTORESIZE, _T("ID_t_camerap"));
        BoxSizer7->Add(t_camerap, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
-       t_elevnumber = new wxStaticText(this, ID_t_elevnumber, wxEmptyString, wxDefaultPosition, wxSize(100,-1), wxST_NO_AUTORESIZE, _T("ID_t_elevnumber"));
+       t_elevnumber = new wxStaticText(this, ID_t_elevnumber, wxEmptyString, wxDefaultPosition, wxSize(150,-1), wxST_NO_AUTORESIZE, _T("ID_t_elevnumber"));
        BoxSizer7->Add(t_elevnumber, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
-       t_elevfloor = new wxStaticText(this, ID_t_elevfloor, wxEmptyString, wxDefaultPosition, wxSize(100,-1), wxST_NO_AUTORESIZE, _T("ID_t_elevfloor"));
+       t_elevfloor = new wxStaticText(this, ID_t_elevfloor, wxEmptyString, wxDefaultPosition, wxSize(150,-1), wxST_NO_AUTORESIZE, _T("ID_t_elevfloor"));
        BoxSizer7->Add(t_elevfloor, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
-       t_object = new wxStaticText(this, ID_t_object, wxEmptyString, wxDefaultPosition, wxSize(100,-1), wxST_NO_AUTORESIZE, _T("ID_t_object"));
-       BoxSizer7->Add(t_object, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
-       t_framerate = new wxStaticText(this, ID_STATICTEXT7, wxEmptyString, wxDefaultPosition, wxSize(100,-1), wxST_NO_AUTORESIZE, _T("ID_STATICTEXT7"));
-       BoxSizer7->Add(t_framerate, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
-       BoxSizer4->Add(BoxSizer7, 0, wxALL|wxALIGN_RIGHT|wxALIGN_TOP, 0);
+       t_object = new wxStaticText(this, ID_t_object, wxEmptyString, wxDefaultPosition, wxSize(150,-1), wxST_NO_AUTORESIZE, _T("ID_t_object"));
+       BoxSizer7->Add(t_object, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
+       t_framerate = new wxStaticText(this, ID_STATICTEXT7, wxEmptyString, wxDefaultPosition, wxSize(150,-1), wxST_NO_AUTORESIZE, _T("ID_STATICTEXT7"));
+       BoxSizer7->Add(t_framerate, 1, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
+       BoxSizer4->Add(BoxSizer7, 0, wxALIGN_RIGHT|wxALIGN_TOP, 5);
        BoxSizer2->Add(BoxSizer4, 0, wxRIGHT|wxALIGN_LEFT|wxALIGN_TOP, 10);
        BoxSizer5 = new wxBoxSizer(wxVERTICAL);
        StaticText11 = new wxStaticText(this, ID_STATICTEXT11, _("Simulator Options"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT11"));
@@ -114,6 +115,9 @@ DebugPanel::DebugPanel(wxWindow* parent,wxWindowID id)
        chkCollisionDetection = new wxCheckBox(this, ID_chkCollisionDetection, _("Collision Detection"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkCollisionDetection"));
        chkCollisionDetection->SetValue(false);
        BoxSizer5->Add(chkCollisionDetection, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
+       chkGravity = new wxCheckBox(this, ID_chkGravity, _("Gravity"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkGravity"));
+       chkGravity->SetValue(false);
+       BoxSizer5->Add(chkGravity, 1, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
        chkFrameLimiter = new wxCheckBox(this, ID_chkFrameLimiter, _("Frame Limiter"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkFrameLimiter"));
        chkFrameLimiter->SetValue(false);
        BoxSizer5->Add(chkFrameLimiter, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
@@ -125,7 +129,7 @@ DebugPanel::DebugPanel(wxWindow* parent,wxWindowID id)
        BoxSizer5->Add(chkAutoShafts, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
        chkFrameSync = new wxCheckBox(this, ID_chkFrameSync, _("Framerate Sync"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkFrameSync"));
        chkFrameSync->SetValue(false);
-       BoxSizer5->Add(chkFrameSync, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
+       BoxSizer5->Add(chkFrameSync, 0, wxBOTTOM|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
        BoxSizer2->Add(BoxSizer5, 0, wxALL|wxALIGN_RIGHT|wxALIGN_TOP, 0);
        BoxSizer1->Add(BoxSizer2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
        BoxSizer3 = new wxBoxSizer(wxVERTICAL);
@@ -141,8 +145,9 @@ DebugPanel::DebugPanel(wxWindow* parent,wxWindowID id)
        SetSizer(BoxSizer1);
        BoxSizer1->Fit(this);
        BoxSizer1->SetSizeHints(this);
-       
+
        Connect(ID_chkCollisionDetection,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&DebugPanel::On_chkCollisionDetection_Click);
+       Connect(ID_chkGravity,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&DebugPanel::On_chkGravity_Click);
        Connect(ID_chkFrameLimiter,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&DebugPanel::On_chkFrameLimiter_Click);
        Connect(ID_chkMainProcessing,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&DebugPanel::On_chkMainProcessing_Click);
        Connect(ID_chkAutoShafts,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&DebugPanel::On_chkAutoShafts_Click);
@@ -166,7 +171,7 @@ DebugPanel::~DebugPanel()
 
 void DebugPanel::On_chkCollisionDetection_Click(wxCommandEvent& event)
 {
-       sbs->EnableCollisions = chkCollisionDetection->GetValue();
+       sbs->camera->EnableCollisions = chkCollisionDetection->GetValue();
 }
 
 void DebugPanel::On_chkFrameLimiter_Click(wxCommandEvent& event)
@@ -212,7 +217,8 @@ void DebugPanel::On_bEditElevator_Click(wxCommandEvent& event)
 void DebugPanel::OnInit()
 {
        //set check boxes
-       chkCollisionDetection->SetValue(sbs->EnableCollisions);
+       chkCollisionDetection->SetValue(sbs->camera->EnableCollisions);
+       chkGravity->SetValue(sbs->camera->GetGravityStatus());
        chkFrameLimiter->SetValue(sbs->FrameLimiter);
        //chkMainProcessing->SetValue();
        chkAutoShafts->SetValue(sbs->AutoShafts);
@@ -271,3 +277,9 @@ wxString TruncateNumber(float value, int decimals)
                return number;
        return number.Truncate(number.find('.') + decimals + 1);
 }
+
+void DebugPanel::On_chkGravity_Click(wxCommandEvent& event)
+{
+       //enables or disables gravity
+       sbs->camera->EnableGravity(chkGravity->GetValue());
+}
index 399c71c..64f06da 100644 (file)
@@ -64,6 +64,7 @@ class DebugPanel: public wxFrame
                static const long ID_STATICTEXT7;
                static const long ID_STATICTEXT11;
                static const long ID_chkCollisionDetection;
+               static const long ID_chkGravity;
                static const long ID_chkFrameLimiter;
                static const long ID_chkMainProcessing;
                static const long ID_chkAutoShafts;
@@ -93,12 +94,14 @@ class DebugPanel: public wxFrame
                void On_bMeshControl_Click(wxCommandEvent& event);
                void On_bInitRealtime_Click(wxCommandEvent& event);
                void On_bEditElevator_Click(wxCommandEvent& event);
+               void On_chkGravity_Click(wxCommandEvent& event);
                //*)
                void OnInit();
 
                //(*Declarations(DebugPanel)
                wxBoxSizer* BoxSizer4;
                wxBoxSizer* BoxSizer6;
+               wxCheckBox* chkGravity;
                wxBoxSizer* BoxSizer5;
                wxBoxSizer* BoxSizer7;
                wxStaticText* t_elevfloor;
index 0c14a73..6446137 100644 (file)
@@ -66,7 +66,6 @@ SBS::SBS()
        IsFalling = false;
        InStairwell = false;
        InElevator = false;
-       EnableCollisions = true;
        IsBuildingsEnabled = false;
        IsColumnFrameEnabled = false;
        IsExternalEnabled = false;
@@ -170,7 +169,6 @@ void SBS::Start()
 
        //initialize camera/actor
        camera->CreateColliders();
-       camera->SetGravity(MetersToFeet(9.806)); // 9.806 m/s/s
 
        //move camera to start location
        camera->SetToStartPosition();
@@ -404,10 +402,6 @@ void SBS::SetupFrame()
        {
                if (RenderOnly == false && InputOnly == false)
                {
-                       //Process gravity
-                       //if (EnableCollisions == true)
-                               //camera->Gravity();
-
                        //Determine floor that the camera is on
                        camera->UpdateCameraFloor();
 
index dae008d..4b5ecae 100644 (file)
--- a/src/sbs.h
+++ b/src/sbs.h
@@ -121,7 +121,6 @@ public:
        bool ElevatorSync; //true if user should move with elevator
        bool FrameLimiter; //frame limiter toggle
        int FrameRate; //max frame rate
-       bool EnableCollisions; //turns collisions on/off
        float HorizScale; //horizontal X/Z scaling multiplier (in feet). Normally is 1
        csArray<csString> UserVariable;
        bool IsBuildingsEnabled; //contains status of buildings object