Sign in to follow this  

space shooting game help

Recommended Posts

I found many source for rotate x-z plane using quaternion, but if I want to write a space shooting game, the problem is how can I also rotate Z-axis. Anyone can help? thanks!

Share this post

Link to post
Share on other sites
Use a 4x4 matrix to handle you position and rotation information. You will then be free to rotate about whatever axis you want as well as translate in the same unit. Otherwise you have to cascade your transform matricies. AFAIK.

Share this post

Link to post
Share on other sites
As an addition to my above post, I suggest you check out this wonderful resource provided by this site.

The use of a 4x4 or quaternion and post multiplication also allows you to avoid gimbal lock.

You will also probably want to implement some sort of SLERP algorithm to smooth things out a bit.

SLERP general definition:

A good resource with some example code:,%20Then%20Not%20Using%20It/

The code from the above:

Quaternion slerp(Quaternion const &v0, Quaternion const &v1, double t) {
// v0 and v1 should be unit length or else
// something broken will happen.

// Compute the cosine of the angle between the two vectors.
double dot = dot_product(v0, v1);

const double DOT_THRESHOLD = 0.9995;
if (dot > DOT_THRESHOLD) {
// If the inputs are too close for comfort, linearly interpolate
// and normalize the result.

Quaternion result = v0 + t*(v1 – v0);
return result;

Clamp(dot, -1, 1); // Robustness: Stay within domain of acos()
double theta_0 = acos(dot); // theta_0 = angle between input vectors
double theta = theta_0*t; // theta = angle between v0 and result

Quaternion v2 = v1 – v0*dot;
v2.normalize(); // { v0, v2 } is now an orthonormal basis

return v0*cos(theta) + v2*sin(theta);

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