[Add] ModelBody::SetRotation().

This commit is contained in:
Allanis 2017-11-19 22:45:44 +00:00
parent 14ee542723
commit df060177d9
8 changed files with 27 additions and 20 deletions

View File

@ -24,7 +24,7 @@ public:
void SetLabel(const char* label) { m_label = label; } void SetLabel(const char* label) { m_label = label; }
std::string& GetLabel(void) { return m_label; } std::string& GetLabel(void) { return m_label; }
unsigned int GetFlags(void) { return m_flags; } unsigned int GetFlags(void) { return m_flags; }
/* Return true if we should apply damage. */ /* Return true if we should do collision response and apply damange. */
virtual bool OnCollision(Body* b, Uint32 flags) { return false; } virtual bool OnCollision(Body* b, Uint32 flags) { return false; }
void SetProjectedPos(const vector3d& projectedPos) { m_projectedPos = projectedPos; } void SetProjectedPos(const vector3d& projectedPos) { m_projectedPos = projectedPos; }
/* Only valid if IsOnScreen() is true. */ /* Only valid if IsOnScreen() is true. */

View File

@ -23,6 +23,12 @@ void DynamicBody::Disable(void) {
dBodyDisable(m_body); dBodyDisable(m_body);
} }
void DynamicBody::SetRotation(const matrix4x4d &r) {
dMatrix3 _m;
r.SaveToOdeMatrix(_m);
dBodySetRotation(m_body, _m);
}
void DynamicBody::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);

View File

@ -10,6 +10,7 @@ class DynamicBody : public ModelBody {
public: public:
DynamicBody(void); DynamicBody(void);
virtual ~DynamicBody(void); virtual ~DynamicBody(void);
virtual void SetRotation(const matrix4x4d& r);
void SetVelocity(vector3d v); void SetVelocity(vector3d v);
void SetAngVelocity(vector3d v); void SetAngVelocity(vector3d v);
void SetMesh(ObjMesh* m); void SetMesh(ObjMesh* m);

View File

@ -33,13 +33,13 @@ public:
} }
/* Row-major. */ /* Row-major. */
void SaveTo3x3Matrix(T* r) { void SaveTo3x3Matrix(T* r) const {
r[0] = cell[0]; r[1] = cell[4]; r[2] = cell[8]; r[0] = cell[0]; r[1] = cell[4]; r[2] = cell[8];
r[3] = cell[1]; r[4] = cell[5]; r[5] = cell[9]; r[3] = cell[1]; r[4] = cell[5]; r[5] = cell[9];
r[6] = cell[2]; r[7] = cell[6]; r[8] = cell[10]; r[6] = cell[2]; r[7] = cell[6]; r[8] = cell[10];
} }
void SaveToOdeMatrix(T r[12]) { void SaveToOdeMatrix(T r[12]) const {
r[0] = cell[0]; r[1] = cell[4]; r[ 2] = cell[ 8]; r[ 3] = 0; r[0] = cell[0]; r[1] = cell[4]; r[ 2] = cell[ 8]; r[ 3] = 0;
r[4] = cell[1]; r[5] = cell[5]; r[ 6] = cell[ 9]; r[ 7] = 0; r[4] = cell[1]; r[5] = cell[5]; r[ 6] = cell[ 9]; r[ 7] = 0;
r[8] = cell[2]; r[9] = cell[6]; r[10] = cell[10]; r[11] = 0; r[8] = cell[2]; r[9] = cell[6]; r[10] = cell[10]; r[11] = 0;

View File

@ -36,7 +36,7 @@ void ModelBody::GeomsSetBody(dBodyID body) {
} }
} }
void ModelBody::SetGeomFromSBREModel(int sbreModel, ObjParams* params) { void ModelBody::SetModel(int sbreModel) {
assert(geoms.size() == 0); assert(geoms.size() == 0);
CollMeshSet* mset = GetModelCollMeshSet(sbreModel); CollMeshSet* mset = GetModelCollMeshSet(sbreModel);
@ -57,15 +57,19 @@ void ModelBody::SetPosition(vector3d p) {
} }
} }
void ModelBody::SetVelocity(vector3d v) {
assert(0);
}
vector3d ModelBody::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 ModelBody::SetRotation(const matrix4x4d& r) {
dMatrix3 _m;
r.SaveToOdeMatrix(_m);
for(unsigned int i = 0; i < geoms.size(); i++) {
dGeomSetRotation(geoms[i], _m);
}
}
void ModelBody::GetRotMatrix(matrix4x4d& m) { void ModelBody::GetRotMatrix(matrix4x4d& m) {
m.LoadFromOdeMatrix(dGeomGetRotation(geoms[0])); m.LoadFromOdeMatrix(dGeomGetRotation(geoms[0]));
} }

View File

@ -12,10 +12,8 @@ public:
ModelBody(void); ModelBody(void);
virtual ~ModelBody(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 virtual void SetRotation(const matrix4x4d& r);
* space stations and will be static relative to their frame of reference. /* Not valid to SetVelocity on these. If you want them to move, use a DynamicBody. */
*/
void SetVelocity(vector3d v);
vector3d GetPosition(void); vector3d GetPosition(void);
void TransformToModelCoords(const Frame* camFrame); void TransformToModelCoords(const Frame* camFrame);
void TransformCameraTo(void); void TransformCameraTo(void);
@ -28,7 +26,7 @@ public:
virtual void Enable(void); virtual void Enable(void);
void TriMeshUpdateLastPos(void); void TriMeshUpdateLastPos(void);
void SetGeomFromSBREModel(int sbreModel, ObjParams* params); void SetModel(int sbreModel);
void RenderSbreModel(const Frame* camFrame, int model, ObjParams* params); void RenderSbreModel(const Frame* camFrame, int model, ObjParams* params);

View File

@ -38,7 +38,7 @@ Ship::Ship(ShipType::Type shipType) : DynamicBody() {
} }
memset(m_thrusters, 0, sizeof(m_thrusters)); memset(m_thrusters, 0, sizeof(m_thrusters));
const ShipType& stype = GetShipType(); const ShipType& stype = GetShipType();
SetGeomFromSBREModel(stype.sbreModel, &params); SetModel(stype.sbreModel);
SetMassDistributionFromCollMesh(GetModelSBRECollMesh(stype.sbreModel)); SetMassDistributionFromCollMesh(GetModelSBRECollMesh(stype.sbreModel));
GeomsSetBody(m_body); GeomsSetBody(m_body);
UpdateMass(); UpdateMass();
@ -207,6 +207,7 @@ static void render_coll_mesh(const CollMesh* m) {
} }
void Ship::Render(const Frame* camFrame) { void Ship::Render(const Frame* camFrame) {
if(!dBodyIsEnabled(m_body)) return;
const ShipType& stype = GetShipType(); const ShipType& stype = GetShipType();
params.angthrust[0] = m_angThrusters[0]; params.angthrust[0] = m_angThrusters[0];
params.angthrust[1] = m_angThrusters[1]; params.angthrust[1] = m_angThrusters[1];

View File

@ -21,12 +21,9 @@ static ObjParams params = {
}; };
SpaceStation::SpaceStation(void) : ModelBody() { SpaceStation::SpaceStation(void) : ModelBody() {
SetGeomFromSBREModel(STATION_SBRE_MODEL, &params); SetModel(STATION_SBRE_MODEL);
matrix4x4d m = matrix4x4d::RotateYMatrix(-M_PI/4); matrix4x4d m = matrix4x4d::RotateYMatrix(M_PI);
dMatrix3 _m; SetRotation(m);
m.SaveToOdeMatrix(_m);
//dGeomSetRotation(m_geom, _m);
//dGeomSetBody(m_geom, 0);
} }
SpaceStation::~SpaceStation(void) { SpaceStation::~SpaceStation(void) {