About Store Forum Documentation Contact



Post Reply 
6 Degree's of Freedom
Author Message
runewake2 Offline
Member

Post: #1
6 Degree's of Freedom
I recently started rewriting my character class. Originally it extended a Kinematic object. Now I'm extending the Character one.

Oddly, the code for manipulating the matrix in the kinematic does not work the same.

PHP Code:
//Kinematic
void Player::RotatePlayer(float pitchfloat yawfloat roll)
{
    
Matrix mat matrix();
    
Quaternion quat Quaternion(matrix());
    
quat.setRotate(pitch + (Cos(Time.time()) / 1500), yaw + (Sin(Time.time()) / 1500), roll);

    
mat.setRotate(quat.axis(), quat.angle());
    
mat.rotate(matrix().axis(), matrix().angle());
    
mat.pos matrix().pos;

    
kinematicMoveTo(mat);


PHP Code:
//Character
void Player::addRotate(float pitchfloat yawfloat roll)
{
    
Matrix mat matrix();
    
Quaternion quat Quaternion(matrix());
    
quat.setRotate(pitch + (Cos(Time.time()) / 1500), yaw + (Sin(Time.time()) / 1500), roll);

    
mat.setRotate(quat.axis(), quat.angle());
    
mat.rotate(matrix().axis(), matrix().angle());
    
mat.pos matrix().pos;

    
matrix(mat);


This causes the player to rotate in all six degrees with the Kinematic codes but the Character code does nothing. It doesn't even flinch. This is not the only variation of rotational codes I used on the Character object, all had little effect.

What am I doing wrong or should I do in order to get my object to rotate correctly?
(This post was last modified: 05-11-2012 06:22 AM by runewake2.)
05-11-2012 06:21 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: 6 Degree's of Freedom
if you take a look at Game::Chr header:
Code:
virtual void   matrix(C Matrix &matrix) {pos(matrix.pos);} // set matrix, only 'matrix.pos' is used in this method
if you want to use Game::Chr then you'd need to operate on virtual animate function, and apply modifications there, it may be difficult without having the game chr sources.
05-11-2012 07:10 AM
Find all posts by this user Quote this message in a reply
runewake2 Offline
Member

Post: #3
RE: 6 Degree's of Freedom
Alright, I got that sorted out, but now I'm having a different problem.

My movement code creates a temporary matrix (mat) and assigns the velocities to that before passing it to the controller.

PHP Code:
Orient ori Orient(matrix());
mat.move(ori.dir forward Time.d() * acceleration);
mat.move(ori.perp up Time.d()  * acceleration);
mat.move(ori.cross() * right Time.d()  * acceleration);

//Now for the brakes:
if (!disableBrake)
{
    
Orient moving Orient(ctrl.actor.vel());
    if (!
forward)
    {
        
Vec vel ctrl.actor.vel() * ori.dir;
        
vel /= 2;
        
mat.move(-vel);
    }
    if (!
right)
    {
        
Vec vel ctrl.actor.vel() * ori.cross();
        
vel /= 2;
        
mat.move(-vel);
    }
    if (!
up)
    {
        
Vec vel ctrl.actor.vel() * ori.perp;
        
vel /= 2;
        
mat.move(-vel);
    }


The first part works correctly and provides the thrust. But the second, braking, part only works when the player's direction is the Zero Vector otherwise it is incorrect and can cause insane amounts of acceleration and other bad things. Clearly this is not the best way to do it but I could find no way to brake an actor mostly adding friction.

The simple way is to just divide the entire players velocity by some arbitrary number which I suppose is "friction" but this causes other problems. I want to apply the brakes only in the directions the player is not moving in. So if the player has a velocity along the X,Y and Z axis (say 10,10,10) and I move to be going directly along the Z axis I want the other two directions to be reduced to 0 (resulting in 0,0,10). This problem becomes a lot more difficult when the player starts moving at a random angle as the reverse thrust is applied to each direction.

As I said the code I am using above works, but only if the player is moving along the zero vector. How would I adapt this to work at any angle?
05-12-2012 03:31 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #4
RE: 6 Degree's of Freedom
Velocity is defined as a direction and a magnitude--or direction and speed. You shouldn't need to transform the velocity vector. That should be your problem with the direction. (I may be wrong here, I'm just starting to use the Essenthel engine. You may find it enlightening to look into vector and matrix math to see and understand what is going on behind the scenes.)
For your reverse motion, I believe your issue is that while holding the brakes, you are constantly adding that backwards vector. Try adding in a check to make sure it's not moving at a 'negative' velocity relative to the direction of travel. In addition, you'll probably want to have your braking power multiplied by the Time.d() as well, so you don't lose your brakes during low frame rates.
Hope that helps.
05-12-2012 09:05 PM
Find all posts by this user Quote this message in a reply
Post Reply