Game Development Community

Matrix rotation woes

by Benj · in Torque Game Engine · 02/04/2007 (9:18 pm) · 1 replies

It seems as though, if i rotate a object manually by matrix, it messes up the objects collision detection.
i had made a console method to point a objects Z axis at 1 normal, and Y axis at another, it seemed to work, until i tried it on some odd surfaces, and tried walking on it.

like this:
ConsoleMethod( SceneObject, PointAt, void, 3, 3, "(2 Normals as 1 String)")
{
MatrixF mat = object->getTransform();
Point3F znormal;
Point3F ynormal;
Point3F tmpx;

dSscanf(argv[2],"%f %f %f %f %f %f",&znormal.x,&znormal.y,&znormal.z,&ynormal.x,&ynormal.y,&ynormal.z);

mCross(znormal,ynormal,tmpx);

tmpx.neg();

mCross(znormal,tmpx,ynormal);

mat.setColumn(0,tmpx);
mat.setColumn(1,ynormal);
mat.setColumn(2,znormal);

object->setTransform(mat);
}

ive been testing it with this code in the crossbow firing function:
%player = %obj.client.player;
%raycast = containerraycast(%player.geteyetransform(),vectoradd(%player.geteyetransform(),vectorscale(%player.geteyevector(),200)),-1,%player);
if(getword(%raycast,0) != 0){
%objhit = getword(%raycast,0);
%thislittlerock = new StaticShape(){
datablock = block;
scale = "0.5 0.5 4";
isblock = true;
normal = getwords(%raycast,4,6);
};
%thislittlerock.settransform(getwords(%raycast,1,3)); //SPC Normal2Rotation(getwords(%raycast,4,6)));
if(%objhit.isblock)
%thislittlerock.pointat(getwords(%raycast,4,6) SPC %objhit.normal);
else
%thislittlerock.pointat(getwords(%raycast,4,6) SPC %player.getforwardvector());
}

its basically stacking blocks, with proper rotations and such.
block is a cube dts i made in blender, scaled.

anyway, if i run upto the hut with the slanted walls on the old stronghold map from 1.4(i imported it into 1.5)
and put a block on the wall on the outside, then try to put one on the side of said block, the raycast seems to malfunction, and be the wrong angle as well. as shown here heres a example

also, if i run to walk up the slanted block, the player character jumps around wildly eventually falling threw it.

this doesn't happen if i just use some math in torque script to set the rotation via a quat, but i lack control over the Y axis direction that way.

is there something i else i have to do to get collisions to work when i manually rotate the matrix?

#1
02/06/2007 (8:24 am)
Fixed!

i just needed to normalize the 3 normals that were going to be the new matrix. works flawlessly now.

like so before the set columns.
tmpx.normalize();
ynormal.normalize();
znormal.normalize();