• 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

Update Quaternion Slowly

11 posts in this topic

Okay, guys I know I'm asking alot of questions, but I have alot alot of work to do to finish the 3D Game Engine I'm working on.

I have a RigidBody, I can rotate it by supplying a new Quaternion value, but here is the problem:

I want to rotate it SLOWLY, something like the following:
[CODE]
// We might need to call this method 500 times from rendering to make the RigidBody rotation is equal to FinalQuaternion

void RotateSlowly(btQuaternion FinalQuaternion)
{
btMatrix3x3 orn = body->getWorldTransform().getBasis();
// Code here to change 'orn' according to FinalQuaternion to keep rotating with certain speed until orn rotation is EQUAL to FinalQuaternion
body->getWorldTransform().setBasis(orn);
}
[/CODE]

How can I do that?
0

Share this post


Link to post
Share on other sites
You can compute the quaternion that would turn orn into FinalQuaternion, with a division. If you want to limit the angle, you force the real part of the quaternion to be at least cos(max_angle/2) and rescale the imaginary part of the quaternion to make it unit-length. I posted some code to do that [url="http://www.gamedev.net/topic/634097-incremental-rotation-towards-target-3d/page__p__4999829#entry4999829"]here[/url].
1

Share this post


Link to post
Share on other sites
@Álvaro: I'm not sure exactly how to implement that to use it with Bullet, I thought about converting the quaternion to euler and supplying the updated value to setYPR but I don't know how should I do it with frame independent, same like the following example:
[CODE]x += speed * elapsedTime; // Frame independent[/CODE]
0

Share this post


Link to post
Share on other sites
What part of what I describe don't you understand? The code I provided uses Boost quaternions, but if you understand what it does, you should be able to write the code to work with any quaternion implementation.
0

Share this post


Link to post
Share on other sites
Some parts I don't understand like:
q.real();
q.unreal();

I'm dealing with btQuaternion which doesn't have those methods, I would prefer using Euler but having a little problem with as I mentioned above.
0

Share this post


Link to post
Share on other sites
q.real() returns the real part of q (duh ;) ). So if q = w + xi + yj + zk, q.real() returns w.
q.unreal() returns a quaternion where the real part has been zeroed out. So if q = w + xi + yj + zk, q.unreal() returns 0 + xi + yj + zk.

In any case, the procedure is this:[list]
[*]Start with q = w + xi + yj + zk
[*]If w is negative, flip the sign of all four components
[*]if w is less than cos(alpha/2), set w to cos(alpha/2) and rescale the vector (x,y,z) so that w^2 + x^2 + y^2 + z^2 = 1.
[/list]
The last part is the trickiest. You have to multiply x, y and z by a constant factor that is computed as sqrt((1-w^2)/(x^2+y^2+z^2)).

Is that clear?
1

Share this post


Link to post
Share on other sites
@Álvaro: I found out that I can do that easily by using quaternion slerp to animate the rotation, how can I know that the rotation is completed when using btQuaternion::slerp?
0

Share this post


Link to post
Share on other sites
[quote name='Medo3337' timestamp='1354431411' post='5006224']
@Álvaro: I found out that I can do that easily by using quaternion slerp to animate the rotation, how can I know that the rotation is completed when using btQuaternion::slerp?
[/quote]

Well, the rotation is completed when you pass a 1 to slerp. How exactly are you calling it?
0

Share this post


Link to post
Share on other sites
I want to know when the rotation animation is completed, here is what I'm doing:
[CODE]
// This method should return true when the rotation is completed, otherwise, return false
bool lookAt(float x, float y, float z, float elapsedTime)
{
btQuaternion FinalQuat = GetLookAtRotation(x, y, z);
btQuaternion currentQuat;
orn.getRotation(currentQuat);
float speed = 0.001f;

// Instead of just setting FinalQuat to the rigidbody, I want to animate it
btQuaternion newQuat = currentQuat.slerp(FinalQuat, elapsedTime * speed);
if (???) // If slerp() have done animating the rotation
{
return true; // Animation completed
} else {
return false;
}
}
[/CODE] Edited by Medo3337
0

Share this post


Link to post
Share on other sites
You are using slerp in a funny way. The second argument is supposed to be a number between 0 and 1 indicating at what point between currentQuat and FinalQuat you want to be. But once you have gone through the code once, the value of currentQuat has changed, so you are moving from one to the other in a non-linear fashion. Anyway, whenever you pass a 1 as the second argument, the result will be FinalQuat.

Why did you give up on the other solution I proposed?
0

Share this post


Link to post
Share on other sites
I don't use Bullet, but looking at the documentation, I think this should work:
[code]btQuaternion diffQuat = (currentQuat.inverse() * FinalQuat).nearest(btQuaternion(1.0, 0.0, 0.0, 0.0));
if (diffQuat.getAngle() > max_angle))
diffQuat.setRotation(diffQuat.getAxis(),max_angle);
btQuaternion newQuat = currentQuat * diffQuat;
[/code]

That code uses a couple of trigonometric functions more than strictly necessary, but given the interface of btQuaternion, it seems to be the easiest way to do it.

Let me know if that works.
0

Share this post


Link to post
Share on other sites
It's not working, basically I want to animate the rotation of a tank cannon, the tank cannon should rotate with certain speed, so the method can look like that:
[CODE]
// Every call will rotate the cannon according to 'rotationSpeed'
bool lookAt(float x, float y, float z, float rotationSpeed, float elapsedTime);
[/CODE]


Here is the idea:
1. The tank see the enemy
2. The tank rotate it's cannon towards the enemy lookAt(enemy.x, enemy.y, enemy.z, 0.1f, elapsedTime);
3. Keep calling lookAt() each frame until lookAt() return true, when lookAt() return true, fire a missile towards the enemy.
0

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