[Change] Renamed rigid body stuff.
This commit is contained in:
parent
40f38a0f58
commit
8ff436c193
@ -4,17 +4,17 @@ SUBDIRS = sbre/
|
|||||||
bin_PROGRAMS = Lephisto3D
|
bin_PROGRAMS = Lephisto3D
|
||||||
Lephisto3D_SOURCES = main.cpp gui_button.cpp gui.cpp gui_fixed.cpp gui_screen.cpp gui_label.cpp glfreetype.cpp \
|
Lephisto3D_SOURCES = main.cpp gui_button.cpp gui.cpp gui_fixed.cpp gui_screen.cpp gui_label.cpp glfreetype.cpp \
|
||||||
objimport.cpp body.cpp space.cpp ship.cpp player.cpp gui_toggle_button.cpp gui_radio_button.cpp \
|
objimport.cpp body.cpp space.cpp ship.cpp player.cpp gui_toggle_button.cpp gui_radio_button.cpp \
|
||||||
gui_radio_group.cpp rigid_body.cpp planet.cpp star.cpp frame.cpp gui_image_button.cpp gui_image.cpp \
|
gui_radio_group.cpp dynamic_body.cpp planet.cpp star.cpp frame.cpp gui_image_button.cpp gui_image.cpp \
|
||||||
gui_image_radio_button.cpp gui_multi_state_image_button.cpp ship_cpanel.cpp gui_widget.cpp sector_view.cpp \
|
gui_image_radio_button.cpp gui_multi_state_image_button.cpp ship_cpanel.cpp gui_widget.cpp sector_view.cpp \
|
||||||
mtrand.cpp world_view.cpp system_view.cpp star_system.cpp sector.cpp system_info_view.cpp generic_system_view.cpp \
|
mtrand.cpp world_view.cpp system_view.cpp star_system.cpp sector.cpp system_info_view.cpp generic_system_view.cpp \
|
||||||
gui_container.cpp date.cpp space_station.cpp space_station_view.cpp static_rigid_body.cpp ship_type.cpp \
|
gui_container.cpp date.cpp space_station.cpp space_station_view.cpp model_body.cpp ship_type.cpp \
|
||||||
info_view.cpp model_coll_mesh_data.cpp
|
info_view.cpp model_coll_mesh_data.cpp
|
||||||
Lephisto3D_LDADD = sbre/libsbre.a
|
Lephisto3D_LDADD = sbre/libsbre.a
|
||||||
|
|
||||||
include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h gui_container.h gui_events.h gui_fixed.h \
|
include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h gui_container.h gui_events.h gui_fixed.h \
|
||||||
gui.h gui_image_button.h gui_image.h gui_image_radio_button.h gui_label.h gui_multi_state_image_button.h gui_radio_button.h \
|
gui.h gui_image_button.h gui_image.h gui_image_radio_button.h gui_label.h gui_multi_state_image_button.h gui_radio_button.h \
|
||||||
gui_radio_group.h gui_screen.h gui_toggle_button.h gui_widget.h libs.h matrix4x4.h mtrand.h objimport.h l3d.h \
|
gui_radio_group.h gui_screen.h gui_toggle_button.h gui_widget.h libs.h matrix4x4.h mtrand.h objimport.h l3d.h \
|
||||||
planet.h player.h rigid_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \
|
planet.h player.h dynamic_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \
|
||||||
system_view.h vector3.h view.h world_view.h date.h space_station.h space_station_view.h static_rigid_body.h gui_iselectable.h \
|
system_view.h vector3.h view.h world_view.h date.h space_station.h space_station_view.h model_body.h gui_iselectable.h \
|
||||||
ship_type.h object.h info_view.h model_coll_mesh_data.h
|
ship_type.h object.h info_view.h model_coll_mesh_data.h
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "libs.h"
|
#include "libs.h"
|
||||||
#include "rigid_body.h"
|
#include "dynamic_body.h"
|
||||||
#include "space.h"
|
#include "space.h"
|
||||||
#include "objimport.h"
|
#include "objimport.h"
|
||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
|
|
||||||
RigidBody::RigidBody(void) : StaticRigidBody() {
|
DynamicBody::DynamicBody(void) : ModelBody() {
|
||||||
m_flags = Body::FLAG_CAN_MOVE_FRAME;
|
m_flags = Body::FLAG_CAN_MOVE_FRAME;
|
||||||
m_body = dBodyCreate(Space::world);
|
m_body = dBodyCreate(Space::world);
|
||||||
dMassSetBox(&m_mass, 1, 50, 50, 50);
|
dMassSetBox(&m_mass, 1, 50, 50, 50);
|
||||||
@ -13,7 +13,7 @@ RigidBody::RigidBody(void) : StaticRigidBody() {
|
|||||||
dBodySetMass(m_body, &m_mass);
|
dBodySetMass(m_body, &m_mass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
|
void DynamicBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
|
||||||
vector3d min = vector3d(FLT_MAX);
|
vector3d min = vector3d(FLT_MAX);
|
||||||
vector3d max = vector3d(-FLT_MAX);
|
vector3d max = vector3d(-FLT_MAX);
|
||||||
for(int i = 0; i < 3*m->nv; i += 3) {
|
for(int i = 0; i < 3*m->nv; i += 3) {
|
||||||
@ -28,21 +28,21 @@ void RigidBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
|
|||||||
dBodySetMass(m_body, &m_mass);
|
dBodySetMass(m_body, &m_mass);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector3d RigidBody::GetAngularMomentum(void) {
|
vector3d DynamicBody::GetAngularMomentum(void) {
|
||||||
matrix4x4d I;
|
matrix4x4d I;
|
||||||
I.LoadFromOdeMatrix(m_mass.I);
|
I.LoadFromOdeMatrix(m_mass.I);
|
||||||
return I * vector3d(dBodyGetAngularVel(m_body));
|
return I * vector3d(dBodyGetAngularVel(m_body));
|
||||||
}
|
}
|
||||||
|
|
||||||
RigidBody::~RigidBody(void) {
|
DynamicBody::~DynamicBody(void) {
|
||||||
dBodyDestroy(m_body);
|
dBodyDestroy(m_body);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetVelocity(vector3d v) {
|
void DynamicBody::SetVelocity(vector3d v) {
|
||||||
dBodySetLinearVel(m_body, v.x, v.y, v.z);
|
dBodySetLinearVel(m_body, v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetAngVelocity(vector3d v) {
|
void DynamicBody::SetAngVelocity(vector3d v) {
|
||||||
dBodySetAngularVel(m_body, v.x, v.y, v.z);
|
dBodySetAngularVel(m_body, v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "body.h"
|
#include "body.h"
|
||||||
#include "static_rigid_body.h"
|
#include "model_body.h"
|
||||||
#include "vector3.h"
|
#include "vector3.h"
|
||||||
#include "matrix4x4.h"
|
#include "matrix4x4.h"
|
||||||
|
|
||||||
class ObjMesh;
|
class ObjMesh;
|
||||||
|
|
||||||
class RigidBody: public StaticRigidBody {
|
class DynamicBody : public ModelBody {
|
||||||
public:
|
public:
|
||||||
RigidBody(void);
|
DynamicBody(void);
|
||||||
virtual ~RigidBody(void);
|
virtual ~DynamicBody(void);
|
||||||
void SetVelocity(vector3d v);
|
void SetVelocity(vector3d v);
|
||||||
void SetAngVelocity(vector3d v);
|
void SetAngVelocity(vector3d v);
|
||||||
void SetMesh(ObjMesh* m);
|
void SetMesh(ObjMesh* m);
|
@ -1,5 +1,5 @@
|
|||||||
#include "libs.h"
|
#include "libs.h"
|
||||||
#include "static_rigid_body.h"
|
#include "model_body.h"
|
||||||
#include "space.h"
|
#include "space.h"
|
||||||
#include "matrix4x4.h"
|
#include "matrix4x4.h"
|
||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
@ -7,24 +7,24 @@
|
|||||||
#include "world_view.h"
|
#include "world_view.h"
|
||||||
#include "model_coll_mesh_data.h"
|
#include "model_coll_mesh_data.h"
|
||||||
|
|
||||||
StaticRigidBody::StaticRigidBody(void): Body() {
|
ModelBody::ModelBody(void): Body() {
|
||||||
triMeshLastMatrixIndex = 0;
|
triMeshLastMatrixIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticRigidBody::~StaticRigidBody(void) {
|
ModelBody::~ModelBody(void) {
|
||||||
SetFrame(0); /* Will remove geom from frame if necessary. */
|
SetFrame(0); /* Will remove geom from frame if necessary. */
|
||||||
for(unsigned int i = 0; i < geoms.size(); i++) {
|
for(unsigned int i = 0; i < geoms.size(); i++) {
|
||||||
dGeomDestroy(geoms[i]);
|
dGeomDestroy(geoms[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::GeomsSetBody(dBodyID body) {
|
void ModelBody::GeomsSetBody(dBodyID body) {
|
||||||
for(unsigned int i = 0; i < geoms.size(); i++) {
|
for(unsigned int i = 0; i < geoms.size(); i++) {
|
||||||
dGeomSetBody(geoms[i], body);
|
dGeomSetBody(geoms[i], body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::SetGeomFromSBREModel(int sbreModel, ObjParams* params) {
|
void ModelBody::SetGeomFromSBREModel(int sbreModel, ObjParams* params) {
|
||||||
assert(geoms.size() == 0);
|
assert(geoms.size() == 0);
|
||||||
CollMeshSet* mset = GetModelCollMeshSet(sbreModel);
|
CollMeshSet* mset = GetModelCollMeshSet(sbreModel);
|
||||||
|
|
||||||
@ -39,33 +39,33 @@ void StaticRigidBody::SetGeomFromSBREModel(int sbreModel, ObjParams* params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::SetPosition(vector3d p) {
|
void ModelBody::SetPosition(vector3d p) {
|
||||||
for(unsigned int i = 0; i < geoms.size(); i++) {
|
for(unsigned int i = 0; i < geoms.size(); i++) {
|
||||||
dGeomSetPosition(geoms[i], p.x, p.y, p.z);
|
dGeomSetPosition(geoms[i], p.x, p.y, p.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::SetVelocity(vector3d v) {
|
void ModelBody::SetVelocity(vector3d v) {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector3d StaticRigidBody::GetPosition(void) {
|
vector3d ModelBody::GetPosition(void) {
|
||||||
const dReal* pos = dGeomGetPosition(geoms[0]);
|
const dReal* pos = dGeomGetPosition(geoms[0]);
|
||||||
return vector3d(pos[0], pos[1], pos[2]);
|
return vector3d(pos[0], pos[1], pos[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::GetRotMatrix(matrix4x4d& m) {
|
void ModelBody::GetRotMatrix(matrix4x4d& m) {
|
||||||
m.LoadFromOdeMatrix(dGeomGetRotation(geoms[0]));
|
m.LoadFromOdeMatrix(dGeomGetRotation(geoms[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::ViewingRotation(void) {
|
void ModelBody::ViewingRotation(void) {
|
||||||
matrix4x4d m;
|
matrix4x4d m;
|
||||||
GetRotMatrix(m);
|
GetRotMatrix(m);
|
||||||
m = m.InverseOf();
|
m = m.InverseOf();
|
||||||
glMultMatrixd(&m[0]);
|
glMultMatrixd(&m[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::TransformCameraTo(void) {
|
void ModelBody::TransformCameraTo(void) {
|
||||||
const dReal* p = dGeomGetPosition(geoms[0]);
|
const dReal* p = dGeomGetPosition(geoms[0]);
|
||||||
matrix4x4d m;
|
matrix4x4d m;
|
||||||
GetRotMatrix(m);
|
GetRotMatrix(m);
|
||||||
@ -74,7 +74,7 @@ void StaticRigidBody::TransformCameraTo(void) {
|
|||||||
glTranslated(-p[0], -p[1], -p[2]);
|
glTranslated(-p[0], -p[1], -p[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::TransformToModelCoords(const Frame* camFrame) {
|
void ModelBody::TransformToModelCoords(const Frame* camFrame) {
|
||||||
vector3d fpos = GetPositionRelTo(camFrame);
|
vector3d fpos = GetPositionRelTo(camFrame);
|
||||||
|
|
||||||
const dReal* r = dGeomGetRotation(geoms[0]);
|
const dReal* r = dGeomGetRotation(geoms[0]);
|
||||||
@ -86,7 +86,7 @@ void StaticRigidBody::TransformToModelCoords(const Frame* camFrame) {
|
|||||||
glMultMatrixd(&m[0]);
|
glMultMatrixd(&m[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::SetFrame(Frame* f) {
|
void ModelBody::SetFrame(Frame* f) {
|
||||||
if(GetFrame()) {
|
if(GetFrame()) {
|
||||||
for(unsigned int i = 0; i < geoms.size(); i++) {
|
for(unsigned int i = 0; i < geoms.size(); i++) {
|
||||||
GetFrame()->RemoveGeom(geoms[i]);
|
GetFrame()->RemoveGeom(geoms[i]);
|
||||||
@ -100,7 +100,7 @@ void StaticRigidBody::SetFrame(Frame* f) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::TriMeshUpdateLastPos(void) {
|
void ModelBody::TriMeshUpdateLastPos(void) {
|
||||||
/* ODE tri mesh likes to know our old position. */
|
/* ODE tri mesh likes to know our old position. */
|
||||||
const dReal* r = dGeomGetRotation(geoms[0]);
|
const dReal* r = dGeomGetRotation(geoms[0]);
|
||||||
vector3d pos = GetPosition();
|
vector3d pos = GetPosition();
|
||||||
@ -115,7 +115,7 @@ void StaticRigidBody::TriMeshUpdateLastPos(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticRigidBody::RenderSbreModel(const Frame* camFrame, int model, ObjParams* params) {
|
void ModelBody::RenderSbreModel(const Frame* camFrame, int model, ObjParams* params) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
class ObjMesh;
|
class ObjMesh;
|
||||||
|
|
||||||
class StaticRigidBody: public Body {
|
class ModelBody: public Body {
|
||||||
public:
|
public:
|
||||||
StaticRigidBody(void);
|
ModelBody(void);
|
||||||
virtual ~StaticRigidBody(void);
|
virtual ~ModelBody(void);
|
||||||
void SetPosition(vector3d p);
|
void SetPosition(vector3d p);
|
||||||
/* Not valid to do SetVelocity on these. They are for huge things like
|
/* Not valid to do SetVelocity on these. They are for huge things like
|
||||||
* space stations and will be static relative to their frame of reference.
|
* space stations and will be static relative to their frame of reference.
|
@ -22,7 +22,7 @@ static ObjParams params = {
|
|||||||
{ "IR-L33T", "ME TOO" },
|
{ "IR-L33T", "ME TOO" },
|
||||||
};
|
};
|
||||||
|
|
||||||
Ship::Ship(ShipType::Type shipType) : RigidBody() {
|
Ship::Ship(ShipType::Type shipType) : DynamicBody() {
|
||||||
m_wheelTransition = 0;
|
m_wheelTransition = 0;
|
||||||
m_wheelState = 0;
|
m_wheelState = 0;
|
||||||
m_dockedWith = 0;
|
m_dockedWith = 0;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "libs.h"
|
#include "libs.h"
|
||||||
#include "rigid_body.h"
|
#include "dynamic_body.h"
|
||||||
#include "ship_type.h"
|
#include "ship_type.h"
|
||||||
#include "sbre/sbre.h"
|
#include "sbre/sbre.h"
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ struct shipstats_t {
|
|||||||
float hyperspace_range;
|
float hyperspace_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Ship : public RigidBody {
|
class Ship : public DynamicBody {
|
||||||
public:
|
public:
|
||||||
Ship(ShipType::Type shipType);
|
Ship(ShipType::Type shipType);
|
||||||
virtual Object::Type GetType(void) { return Object::SHIP; }
|
virtual Object::Type GetType(void) { return Object::SHIP; }
|
||||||
|
@ -132,11 +132,11 @@ static bool _OnCollision(dGeomID g1, dGeomID g2, Object* o1, Object* o2,
|
|||||||
}
|
}
|
||||||
Ship::LaserObj* lobj = static_cast<Ship::LaserObj*>(o2);
|
Ship::LaserObj* lobj = static_cast<Ship::LaserObj*>(o2);
|
||||||
if(o1 == lobj->owner) return false;
|
if(o1 == lobj->owner) return false;
|
||||||
printf("%s (geom flag %x) was shot by %s\n", ((StaticRigidBody::Geom*)o1)->parent->GetLabel().c_str(),
|
printf("%s (geom flag %x) was shot by %s\n", ((ModelBody::Geom*)o1)->parent->GetLabel().c_str(),
|
||||||
((StaticRigidBody::Geom*)o1)->flags, lobj->owner->GetLabel().c_str());
|
((ModelBody::Geom*)o1)->flags, lobj->owner->GetLabel().c_str());
|
||||||
|
|
||||||
if(o1->GetType() == Object::SHIP) {
|
if(o1->GetType() == Object::SHIP) {
|
||||||
RigidBody* rb = (RigidBody*)o1;
|
DynamicBody* rb = (DynamicBody*)o1;
|
||||||
dVector3 start, dir;
|
dVector3 start, dir;
|
||||||
dGeomRayGet(g2, start, dir);
|
dGeomRayGet(g2, start, dir);
|
||||||
dBodyAddForceAtPos(rb->m_body,
|
dBodyAddForceAtPos(rb->m_body,
|
||||||
@ -153,12 +153,12 @@ static bool _OnCollision(dGeomID g1, dGeomID g2, Object* o1, Object* o2,
|
|||||||
int flags = 0;
|
int flags = 0;
|
||||||
/* Geom bodies point to their parents. */
|
/* Geom bodies point to their parents. */
|
||||||
if(o1->GetType() == Object::GEOM) {
|
if(o1->GetType() == Object::GEOM) {
|
||||||
pb1 = static_cast<StaticRigidBody::Geom*>(o1)->parent;
|
pb1 = static_cast<ModelBody::Geom*>(o1)->parent;
|
||||||
flags |= static_cast<StaticRigidBody::Geom*>(o1)->flags;
|
flags |= static_cast<ModelBody::Geom*>(o1)->flags;
|
||||||
} else pb1 = static_cast<Body*>(o1);
|
} else pb1 = static_cast<Body*>(o1);
|
||||||
if(o2->GetType() == Object::GEOM) {
|
if(o2->GetType() == Object::GEOM) {
|
||||||
pb2 = static_cast<StaticRigidBody::Geom*>(o2)->parent;
|
pb2 = static_cast<ModelBody::Geom*>(o2)->parent;
|
||||||
flags |= static_cast<StaticRigidBody::Geom*>(o2)->flags;
|
flags |= static_cast<ModelBody::Geom*>(o2)->flags;
|
||||||
} else pb2 = static_cast<Body*>(o2);
|
} else pb2 = static_cast<Body*>(o2);
|
||||||
|
|
||||||
printf("Collision flags %x\n", flags);
|
printf("Collision flags %x\n", flags);
|
||||||
|
@ -20,7 +20,7 @@ static ObjParams params = {
|
|||||||
{ "Hello you!", "CATZ" },
|
{ "Hello you!", "CATZ" },
|
||||||
};
|
};
|
||||||
|
|
||||||
SpaceStation::SpaceStation(void) : StaticRigidBody() {
|
SpaceStation::SpaceStation(void) : ModelBody() {
|
||||||
SetGeomFromSBREModel(STATION_SBRE_MODEL, ¶ms);
|
SetGeomFromSBREModel(STATION_SBRE_MODEL, ¶ms);
|
||||||
matrix4x4d m = matrix4x4d::RotateYMatrix(-M_PI/4);
|
matrix4x4d m = matrix4x4d::RotateYMatrix(-M_PI/4);
|
||||||
dMatrix3 _m;
|
dMatrix3 _m;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "libs.h"
|
#include "libs.h"
|
||||||
#include "static_rigid_body.h"
|
#include "model_body.h"
|
||||||
|
|
||||||
class SpaceStation : public StaticRigidBody {
|
class SpaceStation : public ModelBody {
|
||||||
public:
|
public:
|
||||||
SpaceStation(void);
|
SpaceStation(void);
|
||||||
virtual ~SpaceStation(void);
|
virtual ~SpaceStation(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user