A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by ryj3k » Thu Apr 02, 2009 3:29 am
I know I always have problems, right?
But I also know, that another newbie could use knowlege You advanced could give.
So, the problem is that I'd like to set initial rotation. Lets take a cube.
I've such code in my app:
- Code: Select all
//Create vector with cube dimensions
dVector cubeSize(10.0f,10.0f,10.0f,1.0f);
//Create vector with cube location
dMatrix cubeLocation(GetIdentityMatrix());
//Setting initial position
cubeLocation.m_posit.m_y = 50.0f;
//!Trying to change rotation of cube anyhow!
cubeLocation.RotateVector(dVector(1.5f,0.5f,0.5f,1.0f));
//Preparin float for irrlicht
float irrCubeXSize = cubeSize.m_x*NEWTONTOIRR;
//Create vector with location for irrlicht
vector3df irrCubeLocation(cubeLocation.m_posit.m_x, cubeLocation.m_posit.m_y, cubeLocation.m_posit.m_z);
irrCubeLocation*=NEWTONTOIRR;
//Creating cube in irrlicht and newton
cube = sceneManager->addCubeSceneNode(irrCubeXSize, 0, 1,irrCubeLocation, vector3df(0,0,0), vector3df(1.0f,1.0f,1.0f));
if(cube)
{
cube->setMaterialFlag(EMF_LIGHTING, false);
cube->setMaterialTexture(0, videoDriver->getTexture("2.jpg"));
}
collision = NewtonCreateBox (nWorld, cubeSize.m_x, cubeSize.m_y, cubeSize.m_z, NULL);
cubeBody = NewtonCreateBody(nWorld, collision);
//Setting all settings
NewtonBodySetUserData(cubeBody, cube);
NewtonBodySetDestructorCallback(cubeBody, PhysicsBodyDestructor);
NewtonBodySetTransformCallback(cubeBody, PhysicsSetTransform);
NewtonBodySetForceAndTorqueCallback(cubeBody, PhysicsApplyForceAndTorque);
NewtonBodySetMassMatrix(cubeBody, 1.0f,1.0f,1.0f,1.0f);
// HERE WE GO - Why doesn't it work? (THE NEXT 2 LINES)
NewtonBodySetMatrix (cubeBody, &cubeLocation[0][0]);
PhysicsSetTransform (cubeBody, &cubeLocation[0][0]);
NewtonReleaseCollision(nWorld, collision);
Phisics set transform is a callback function, but it should work anywhere, right?
-
ryj3k
-
- Posts: 10
- Joined: Tue Mar 31, 2009 5:54 pm
by Julio Jerez » Thu Apr 02, 2009 9:20 am
You can call NewtonBodySetMatrix
SetTrasform is called afte teh body matrix is set by a integration step, calling yousefl will have no effect.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by ryj3k » Thu Apr 02, 2009 11:01 am
Thanks for reply Julio,
I call NewtonBodySetMatrix (cubeBody, &cubeLocation[0][0]); in the line before the last, but still it doesn't give effect.
-
ryj3k
-
- Posts: 10
- Joined: Tue Mar 31, 2009 5:54 pm
by Julio Jerez » Thu Apr 02, 2009 1:16 pm
NewtonBodySetMatrix (cubeBody, &cubeLocation[0][0]);
set the transofmation o fteh ridig body
you need to set the rotaion of teh vidual body whn eth call back is called,
'you can implemnet debud display to see the body collision shape, and see if the orientation is correct.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by ryj3k » Thu Apr 02, 2009 5:13 pm
We misundestood
Everything during the scene playing is ok, transforms as should, but id like to set rotation of some objects before the scene starts.
And I couldn't do it within NewtonBodySetMatrix cuz it doesn't work.
I hope You'll unerstand me now
-
ryj3k
-
- Posts: 10
- Joined: Tue Mar 31, 2009 5:54 pm
by Julio Jerez » Thu Apr 02, 2009 10:33 pm
NewtonBodySetMatrix is the function for setting the position and oriention of a body, before after or during simulation.
the callback will only be called for a update step, thefroe teh visual matrix will no changed only you call a newton update.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 23 guests