Moderators: Sascha Willems, walaber
Neo wrote:you mean I have to set the matix maunaully!?
IMeshSceneNode *floor=smgr->addCubeSceneNode(500);
//
add texture here
//
floor->setScale(vector3df(1,0.01f,1));//scale the y aixs,because I want a plate, not a cube box
floor->setPosition(vector3df(0,-30,0));
aabbox3df fbox=floor->getTransformedBoundingBox();
vector3df sz=fbox.getExtent();
matrix4 mt=floor->getRelativeTransformation();
// assign our axis vectors to that matrix
vector3df *x = (vector3df*)&mt.pointer()[0]; // 1st. row
vector3df *y = (vector3df*)&mt.pointer()[4]; // 2nd. row
vector3df *z = (vector3df*)&mt.pointer()[8];
// extract scale
float scaleX = x->length();
float scaleY = y->length();
float scaleZ = z->length();
// normalize matrix
*x /= scaleX;
*y /= scaleY;
*z /= scaleZ;
// matrix now ready for newton
NewtonCollision*coll=NewtonCreateBox(nWorld,sz.X,sz.Y,sz.Z,shapeID++,NULL);
// but, we're back to a cube now, so scale the collision to become a plate as we want
NewtonCollisionSetScale (coll, scaleX, scaleY, scaleZ);
NewtonBody* floorBd=NewtonCreateBody(nWorld,coll,&mt.pointer()[0]);
NewtonBodySetTransformCallback(floorBd,transformCallback);
NewtonBodySetUserData(floorBd,static_cast<void*>(floor));
JoeJ wrote:i don't know your mathlib
let me know if it works...
template <class T>
inline CMatrix4<T>& CMatrix4<T>::setRotationDegrees( const vector3d<T>& rotation )
{
return setRotationRadians( rotation * core::DEGTORAD );//const f32 DEGTORAD = PI / 180.0f;
}
template <class T>
inline CMatrix4<T>& CMatrix4<T>::setRotationRadians( const vector3d<T>& rotation )
{
const f64 cr = cos( rotation.X );
const f64 sr = sin( rotation.X );
const f64 cp = cos( rotation.Y );
const f64 sp = sin( rotation.Y );
const f64 cy = cos( rotation.Z );
const f64 sy = sin( rotation.Z );
M[0] = (T)( cp*cy );
M[1] = (T)( cp*sy );
M[2] = (T)( -sp );
const f64 srsp = sr*sp;
const f64 crsp = cr*sp;
M[4] = (T)( srsp*cy-cr*sy );
M[5] = (T)( srsp*sy+cr*cy );
M[6] = (T)( sr*cp );
M[8] = (T)( crsp*cy+sr*sy );
M[9] = (T)( crsp*sy-sr*cy );
M[10] = (T)( cr*cp );
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
}
template <class T>
inline CMatrix4<T>& CMatrix4<T>::setScale( const vector3d<T>& scale )
{
M[0] = scale.X;
M[5] = scale.Y;
M[10] = scale.Z;
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
}
template <class T>
inline CMatrix4<T>& CMatrix4<T>::setTranslation( const vector3d<T>& translation )
{
M[12] = translation.X;
M[13] = translation.Y;
M[14] = translation.Z;
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
}
virtual core::matrix4 getRelativeTransformation() const
{
core::matrix4 mat;
mat.setRotationDegrees(RelativeRotation);
mat.setTranslation(RelativeTranslation);
if (RelativeScale != core::vector3df(1.f,1.f,1.f))
{
core::matrix4 smat;
smat.setScale(RelativeScale);
mat *= smat;
}
return mat;
}
IMeshSceneNode *floor=smgr->addCubeSceneNode(500);
//
add texture here
//
floor->setScale(vector3df(1,0.01f,1));//scale the y aixs,because I want a plate, not a cube box
floor->setPosition(vector3df(0,-30,0));
aabbox3df fbox=floor->getTransformedBoundingBox();
vector3df sz=fbox.getExtent();
matrix4 mt=floor->getRelativeTransformation();
// assign our axis vectors to that matrix
vector3df *x = (vector3df*)&mt.pointer()[0]; // 1st. row
vector3df *y = (vector3df*)&mt.pointer()[4]; // 2nd. row
vector3df *z = (vector3df*)&mt.pointer()[8];
// extract scale
float scaleX = x->length();
float scaleY = y->length();
float scaleZ = z->length();
// normalize matrix
*x /= scaleX;
*y /= scaleY;
*z /= scaleZ;
// try to fix position too, if necessary...
vector3df *pos = (vector3df*)&mt.pointer()[12]; // last row as vector
pos = floor->getPosition();
// or hardcode it for this single example: pos = vector3df(0,-30,0);
// matrix now ready for newton
NewtonCollision*coll=NewtonCreateBox(nWorld,sz.X,sz.Y,sz.Z,shapeID++,NULL);
// but, we're back to a cube now, so scale the collision to become a plate as we want
NewtonCollisionSetScale (coll, scaleX, scaleY, scaleZ);
NewtonBody* floorBd=NewtonCreateBody(nWorld,coll,&mt.pointer()[0]);
NewtonBodySetTransformCallback(floorBd,transformCallback);
NewtonBodySetUserData(floorBd,static_cast<void*>(floor));
vector3df *x = (vector3df*)(&mt.pointer()[0]);// 1st. row
vector3df *y = (vector3df*)(&mt.pointer()[4]); // 2nd. row
vector3df *z = (vector3df*)(&mt.pointer()[8]);
x->normalize();
y->normalize();
z->normalize();
pos = floor->getPosition();
mat.setTransition(pos);
Julio Jerez wrote:where those teh assert happens?
IMeshSceneNode *bullet=smgr->addCubeSceneNode(1);
bullet->setMaterialFlag(video::EMF_LIGHTING,false);
bullet->setMaterialTexture(0,driver->getTexture("F:/myGame/Irr/tankwar/tankwar/sfx/env/common/grass.jpg"));
bullet->setPosition(vector3df(100,-20,70));
bullet->setScale(vector3df(2,1,1));//you see a normal scale, not a freak one
//Newton body
aabbox3df fbox=bullet->getTransformedBoundingBox();
vector3df sz=fbox.getExtent()*IrrToNewton;//for simulation purpose I set this value to 0.1
matrix4 mt=bullet->getRelativeTransformation(),mat2;
mt.setTranslation(mt.getTranslation()*IrrToNewton);
NewtonCollision* coll=NewtonCreateCylinder(nWorld,sz.Y/2,sz.Z,100,NULL);
NewtonBody* bulletBd=NewtonCreateBody(nWorld,coll,&mt.pointer()[0]);
NewtonBodySetTransformCallback(bulletBd,transformCallback);
NewtonBodySetUserData(bulletBd,static_cast<void*>(bullet));
2.0000000 0.00000000 0.00000000 0.00000000
0.00000000 1.0000000 0.00000000 0.00000000
0.00000000 0.00000000 1.0000000 0.00000000
10.000000 -2.0000000 7.0000000 1.0000000
JoeJ wrote:So the y value was scaled down from -30 to -3.
But you set the scale: (1, 0.01, 1).
Now i'm confused, because -30 * 0.01 doesn't equal -3
Maybe there's a typo somewhere?
mt.makeIdentity();
mt.setTranslation(bullet->getPosition()*IrrToNewton);
vector3df scale=bullet->getScale()*IrrToNewton;
NewtonCollision* coll=NewtonCreateCylinder(nWorld,sz.Y/2,sz.Z,bulletShapeID++,NULL);
NewtonCollisionSetScale(coll,scale.X,scale.Y,scale.Z);
NewtonBody* bulletBd=NewtonCreateBody(nWorld,coll,&mt.pointer()[0]);
belfegor wrote:@neo
Why dont you prescale your models in modeling program instead in code?
Also why dont you use 1.0f (one) unit as 1 meter and then you can skip all "scale" conversion (IrrToNewton) ?
JoeJ wrote:I'm actually on OSX and can't access Newton source.
But i'd guess you did something illegal with that convex hull...
Or one of the edges from the mesh has zero length, or double sided polygons... something like that.
When posting assert also post Code Line Number and Stack Trace too, if possible.
EDIT: Keep belfegors tip in mind - it's always better to avoid scaling if possible.
Users browsing this forum: No registered users and 1 guest