• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Medo Mex

RigidBody Rotation

12 posts in this topic

Lets say that I have a tank and want this tank to rotate and look at another area, how do I complete the following code to make the tank rotate 'slightly' every time this method is called?

void RotateLeft(float timeElapsed)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[0];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
btTransform worldTrans;
worldTrans = body->getCenterOfMassTransform();

// ***** Need the rest of the code to rotate the tank *****
}
}
0

Share this post


Link to post
Share on other sites
I'm using bullet physics for my game and this is how I rotate character in the game.

[CODE]
btMatrix3x3 orn = m_pRigidBody->getWorldTransform().getBasis(); //get basis of world transformation
orn *= btMatrix3x3(btQuaternion(axis, radians)); //Multiply it by rotation matrix
m_pRigidBody->getWorldTransform().setBasis(orn); //set new rotation for the object
[/CODE]

m_pRigidBody is an object of btRigidBody*. To represent rotation all you need is 3x3 matrix (4th row and column are to enable translation). So you get basis of world transform and then multiply it by rotation matrix( created with the help of quaternion, where the [b]axis [/b]is axis of rotation and [b]radians [/b]is angle in radians). After that all you have to do is to update basis of your world transform.
For more information about quaternions I would recommend visiting [url="http://3dgep.com/?p=1815"]this link[/url].

I hope it helps;) Edited by DgekGD
1

Share this post


Link to post
Share on other sites
Just to add, if your trouble is with making it rotate at a fixed (slow?) rate based on elapsed time, you'll just multiply your desired rad/sec turning rate by the elapsed time in sec.
0

Share this post


Link to post
Share on other sites
For example, if you use xna math library, you can create XMMATRIX using XMMatrixRotationRollPitchYaw method.

Get current physics object transform:
[CODE]
XMMATRIX transform = btTransform_to_XMMATRIX(m_pRigidBody->getWorldTransform() ); //get basis of world transformation
[/CODE]

Create rotation you need:
[CODE]
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(angle, angle, angle);
[/CODE]

//Get final transform
[CODE]
btTransform finalTransform = XMMATRIX_to_btTansform(transform * rotation);
[/CODE]

Finally, apply your transform
[CODE]
m_pRigidBody->setWorldTransform(finalTransform);
[/CODE]

Here, take a look at conversion methods:
[CODE]
static btTransform XMMATRIX_to_btTransform( XMMATRIX const & mat )
{
// convert from XMMATRIX to btTransform (Bullet Physics)
btMatrix3x3 bulletRotation;
btVector3 bulletPosition;

// copy rotation matrix
for ( int row=0; row<3; ++row )
for ( int column=0; column<3; ++column )
bulletRotation[row][column] = mat.m[column][row];

// copy position
for ( int column=0; column<3; ++column )
bulletPosition[column] = mat.m[3][column];

return btTransform( bulletRotation, bulletPosition );
}
static XMMATRIX btTransform_to_XMMATRIX( XMMATRIX const & trans )
{
XMMATRIX returnValue;
// convert from btTransform (BulletPhysics) to XMMATRIX
btMatrix3x3 const & bulletRotation = trans.getBasis();
btVector3 const & bulletPosition = trans.getOrigin();

// copy rotation matrix
for ( int row=0; row<3; ++row )
for ( int column=0; column<3; ++column )
returnValue.m[row][column] = bulletRotation[column][row];

// copy position
for ( int column=0; column<3; ++column )
returnValue.m[3][column] = bulletPosition[column];

return returnValue;
}

[/CODE]

Take a note, that XMMATRIX is in row-major format and btTransform is column-major, that's why you swap column/row in these methods!
1

Share this post


Link to post
Share on other sites
@DgekGD: I'm not using XNA, I'm using DirectX 9 and Bullet Physics.

Here is what I'm looking for:
[CODE]
float pitch, yaw, roll;
// Code to get pitch, yaw, roll from rigidbody here...
yaw+=0.1;
// Code to apply the new pitch, yaw, roll to the rigidbody here...
[/CODE]
0

Share this post


Link to post
Share on other sites
I didn't mean xna framework, just math defined in xnamath. It was just an example, you can use D3DXMATRIX exactly the same way.

Anyway, to apply new pitch, yaw and roll to your body you have to create transformation matrix!
Using:
XMMatrixRotationRollPitchYaw(Pitch, Yaw, Roll); or
D3DXMatrixRotationYawPitchRoll(pResultMatrix, Yaw, Pitch, Roll) or maybe your own math library class.

Then you'll have to convert this class to btTransform(matrix class which Bullet Physics uses for computation);

That's how you would increment yaw:
[CODE]
yaw+= 0.1;
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
[/CODE]
0

Share this post


Link to post
Share on other sites
[quote name='Medo3337' timestamp='1354222083' post='5005446']
@DgekGD: I'm not using XNA, I'm using DirectX 9 and Bullet Physics.
[/quote]
xnamath is a library for directx, actually, not referring to the XNA framework for .NET.

Anyway, you can use D3DXMatrixRotationYawPitchRoll:
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205361(v=vs.85).aspx"]http://msdn.microsof...1(v=vs.85).aspx[/url]

Edit: DAH, too slow. Edited by BCullis
0

Share this post


Link to post
Share on other sites
I know all of that, the problem I'm having is that I need to get pitch, yaw, roll from [i]bullet physics[/i] and set the updated value to [i]bullet physics[/i].

So here is EXACTLY what I mean:
// Add code to get pitch, yaw, roll from [b]btRigidBody[/b]
pitch+=0.1f;
yaw+=0.2f;
roll+=0.1f;
// Add code to apply the new pitch, yaw, roll to [b]btRigidBody[/b]

If someone could update the two commented lines with the appropriate code, it will be exactly what I want. Edited by Medo3337
0

Share this post


Link to post
Share on other sites
What's the problem with creating rotation matrix D3DXMatrixRotationYawPitchRoll(pResult, 0.2, 0.1, 0.1);

Multiplying current transformation matrix with this one will exactly do what you want: Apply
pitch+=0.1f;
yaw+=0.2f;
roll+=0.1f;
to btRigidBody. Edited by DgekGD
0

Share this post


Link to post
Share on other sites
A little digging in the bullet docs revealed:
btMatrix3x3::setEulerYPR ( const btScalar & yaw,
const btScalar & pitch,
const btScalar & roll
)

So I'm assuming you could use that to create a btMatrix3x3, and then apply that to a btTransform's origin that can be applied to the btRigidBody.

[quote]
If someone could update the two commented lines with the appropriate code, it will be exactly what I want.
[/quote]

No one is here to just write your code for you. You're explicitly asking people to do that. Try and have a little courtesy, it's a forum for information sharing, not task orders. Edited by BCullis
2

Share this post


Link to post
Share on other sites
You got pretty much exactly what you wanted in the first post.
Here its modified with setting yaw, pitch and roll:

[quote name='DgekGD' timestamp='1354198605' post='5005293']
btMatrix3x3 orn = m_pRigidBody->getWorldTransform().getBasis(); //get basis of world transformation
btMatrix ypr;
ypr.setEulerYPR(0.2f,0.1f,0.1f);
orn *= ypr //Multiply it by rotation matrix, yaw, pitch, roll
m_pRigidBody->getWorldTransform().setBasis(orn); //set new rotation for the object
[/quote]

Edit:
[quote]
No one is here to just write your code for you
[/quote]

Oops :) Edited by Olof Hedman
1

Share this post


Link to post
Share on other sites
@Olof Hedman: That was exactly what I was looking for! Thank you!

@BCullis:
[quote]No one is here to just write your code for you.[/quote]
Trust me, writing 5 lines of code is easier to understand and will save a lot of time ;)
-1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0