[Add] ModelBody::SetRotation().
This commit is contained in:
parent
14ee542723
commit
df060177d9
@ -24,7 +24,7 @@ public:
|
||||
void SetLabel(const char* label) { m_label = label; }
|
||||
std::string& GetLabel(void) { return m_label; }
|
||||
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; }
|
||||
void SetProjectedPos(const vector3d& projectedPos) { m_projectedPos = projectedPos; }
|
||||
/* Only valid if IsOnScreen() is true. */
|
||||
|
@ -23,6 +23,12 @@ void DynamicBody::Disable(void) {
|
||||
dBodyDisable(m_body);
|
||||
}
|
||||
|
||||
void DynamicBody::SetRotation(const matrix4x4d &r) {
|
||||
dMatrix3 _m;
|
||||
r.SaveToOdeMatrix(_m);
|
||||
dBodySetRotation(m_body, _m);
|
||||
}
|
||||
|
||||
void DynamicBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
|
||||
vector3d min = vector3d(FLT_MAX);
|
||||
vector3d max = vector3d(-FLT_MAX);
|
||||
|
@ -10,6 +10,7 @@ class DynamicBody : public ModelBody {
|
||||
public:
|
||||
DynamicBody(void);
|
||||
virtual ~DynamicBody(void);
|
||||
virtual void SetRotation(const matrix4x4d& r);
|
||||
void SetVelocity(vector3d v);
|
||||
void SetAngVelocity(vector3d v);
|
||||
void SetMesh(ObjMesh* m);
|
||||
|
@ -33,13 +33,13 @@ public:
|
||||
}
|
||||
|
||||
/* Row-major. */
|
||||
void SaveTo3x3Matrix(T* r) {
|
||||
void SaveTo3x3Matrix(T* r) const {
|
||||
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[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[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;
|
||||
|
@ -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);
|
||||
CollMeshSet* mset = GetModelCollMeshSet(sbreModel);
|
||||
|
||||
@ -57,15 +57,19 @@ void ModelBody::SetPosition(vector3d p) {
|
||||
}
|
||||
}
|
||||
|
||||
void ModelBody::SetVelocity(vector3d v) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
vector3d ModelBody::GetPosition(void) {
|
||||
const dReal* pos = dGeomGetPosition(geoms[0]);
|
||||
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) {
|
||||
m.LoadFromOdeMatrix(dGeomGetRotation(geoms[0]));
|
||||
}
|
||||
|
@ -12,10 +12,8 @@ public:
|
||||
ModelBody(void);
|
||||
virtual ~ModelBody(void);
|
||||
void SetPosition(vector3d p);
|
||||
/* 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.
|
||||
*/
|
||||
void SetVelocity(vector3d v);
|
||||
virtual void SetRotation(const matrix4x4d& r);
|
||||
/* Not valid to SetVelocity on these. If you want them to move, use a DynamicBody. */
|
||||
vector3d GetPosition(void);
|
||||
void TransformToModelCoords(const Frame* camFrame);
|
||||
void TransformCameraTo(void);
|
||||
@ -28,7 +26,7 @@ public:
|
||||
virtual void Enable(void);
|
||||
|
||||
void TriMeshUpdateLastPos(void);
|
||||
void SetGeomFromSBREModel(int sbreModel, ObjParams* params);
|
||||
void SetModel(int sbreModel);
|
||||
|
||||
void RenderSbreModel(const Frame* camFrame, int model, ObjParams* params);
|
||||
|
||||
|
@ -38,7 +38,7 @@ Ship::Ship(ShipType::Type shipType) : DynamicBody() {
|
||||
}
|
||||
memset(m_thrusters, 0, sizeof(m_thrusters));
|
||||
const ShipType& stype = GetShipType();
|
||||
SetGeomFromSBREModel(stype.sbreModel, ¶ms);
|
||||
SetModel(stype.sbreModel);
|
||||
SetMassDistributionFromCollMesh(GetModelSBRECollMesh(stype.sbreModel));
|
||||
GeomsSetBody(m_body);
|
||||
UpdateMass();
|
||||
@ -207,6 +207,7 @@ static void render_coll_mesh(const CollMesh* m) {
|
||||
}
|
||||
|
||||
void Ship::Render(const Frame* camFrame) {
|
||||
if(!dBodyIsEnabled(m_body)) return;
|
||||
const ShipType& stype = GetShipType();
|
||||
params.angthrust[0] = m_angThrusters[0];
|
||||
params.angthrust[1] = m_angThrusters[1];
|
||||
|
@ -21,12 +21,9 @@ static ObjParams params = {
|
||||
};
|
||||
|
||||
SpaceStation::SpaceStation(void) : ModelBody() {
|
||||
SetGeomFromSBREModel(STATION_SBRE_MODEL, ¶ms);
|
||||
matrix4x4d m = matrix4x4d::RotateYMatrix(-M_PI/4);
|
||||
dMatrix3 _m;
|
||||
m.SaveToOdeMatrix(_m);
|
||||
//dGeomSetRotation(m_geom, _m);
|
||||
//dGeomSetBody(m_geom, 0);
|
||||
SetModel(STATION_SBRE_MODEL);
|
||||
matrix4x4d m = matrix4x4d::RotateYMatrix(M_PI);
|
||||
SetRotation(m);
|
||||
}
|
||||
|
||||
SpaceStation::~SpaceStation(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user