Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Fucking matrices

Name: Anonymous 2012-08-29 13:57

I'm pretty shitty with matrices, I've noticed. I've got a normalized vector pointing at a certain direction.
I've been trying to make a rotation matrix that turns a (1,0,0) the same as the direction vector. I seem to be doing something wrong as the z field of the vector is wrong after I've applied the rotation matrix. Could any of you take a look at it?
The language is C++, the utility is DirectX although I am not allowed to use finished functions like D3DXMatrixRotationAxis() or D3DXVec3TransformCoord(). I need the rotation matrix to be correct so I can invert it, and rotate the camera view matrix to then rotate along the x-axis. In other words, I am trying to rotate my view matrix along a fixed axis, but it stops at simply finding the rotation matrix for the direction vector.

void Camera::makeRotationMatrix( D3DXMATRIX *out, D3DXVECTOR3 *direction )
{
D3DXVECTOR3 x_dir(0.0,0.0,1.0), y_dir;
    double d = direction->z;
    if(d>-0.999999999 && d<0.999999999) //to avoid normalizing in special cases
    {
        x_dir=x_dir-(*direction)*d;
        normalizeVector3(&x_dir);
        crossVector3(&y_dir, direction, &x_dir);
    }
    else
    {
        x_dir.x = direction->z;
        x_dir.y = 0;
        x_dir.z = -direction->x;

        y_dir.x = 0;
        y_dir.y = 1;
        y_dir.z = 0;
    }
    //the default arrow is pointing along the x-axis
    out->_11 = direction->x;
    out->_12 = direction->y;
    out->_13 = direction->z;
    out->_14 = 0;
    out->_21 = y_dir.x;
    out->_22 = y_dir.y;
    out->_23 = y_dir.z;
    out->_24 = 0;
    out->_31 = x_dir.x;
    out->_32 = x_dir.y;
    out->_33 = x_dir.z;
    out->_34 = 0;
    out->_41 = 0;
    out->_42 = 0;
    out->_43 = 0;
    out->_44 = 1;
}

Name: Anonymous 2012-08-29 13:59

well shit. I accidentally posted it without finishing.

>continue
out->_21 = y_dir.x;
out->_22 = y_dir.y;
out->_23 = y_dir.z;
out->_24 = 0;
out->_31 = x_dir.x;
out->_32 = x_dir.y;
out->_33 = x_dir.z;
out->_34 = 0;
out->_41 = 0;
out->_42 = 0;
out->_43 = 0;
out->_44 = 1;
}



void Camera::normalizeVector3( D3DXVECTOR3 *vector )
{
    float length = sqrt( pow(vector->x,2) + pow(vector->y,2) + pow(vector->z,2) );
    vector->x /= length;
    vector->y /= length;
    vector->z /= length;
}
void Camera::crossVector3( D3DXVECTOR3 *out,D3DXVECTOR3 *first, D3DXVECTOR3 *second )
{
    float x = first->y*second->z - first->z*second->y;
    float y = first->z*second->x - first->x*second->z;
    float z = first->x*second->y - first->y*second->x;
    out->x = x;
    out->y = y;
    out->z = z;
}

Name: Anonymous 2012-08-29 15:42

Where's the code?

Name: Anonymous 2012-08-29 16:03

very funny.

Here's the result after one frame.
direction vector: (-0.97541010,1.9924684e-009,0.22039773)
the (1,0,0) vector transformed using the rotation matrix: (-0.97541010, -1.9924682e-009, -0.21497817)

Name: Anonymous 2012-08-29 17:36

Code goes in [code] tags. I don't see any [code] tags.

Name: Anonymous 2012-08-29 18:13

>>5
% grep -r [code\] /src
%


I guess /src is empty !

Name: Anonymous 2012-08-29 18:43

If you're confused as to how a library works, simply download the source code for it and read it.

Name: op 2012-08-30 12:39

you're all a bunch of faggots.
oh hey, look at that...
Also, this is why I go to /b/ for everything.
You're all worse than grammar nazis.
Thanks for nothing.

Name: Anonymous 2012-08-30 12:46

Goodbye stupid goy

Name: Anonymous 2012-08-30 12:48

>>8
Cool \[code] fail, bro.

Name: Anonymous 2012-08-30 14:30


Don't change these.
Name: Email:
Entire Thread Thread List