Jump to content
  • Advertisement
Sign in to follow this  
Godden

matrix multiplication help

This topic is 5164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, my problem is, i have a cube made up 6 sides each side of 4 points making 24 points in total, each one of these points is a vector (ie x,y,z co-ordinates). now to rotate my cube i do to everypoint xrotate[3][3] = {{1,0,0}, {0, cos(xspin), sin(xspin)}, {(0, -sin(xspin), cos(xspin))}} cubeSide1 = matrixMultiplication(xrotate,cubeSide1); CVector3 matrixMultiplication(float vect[][3], CVector3 hello) { float a = (vect[0][0] * hello.x) + (vect[1][0] * hello.y) + (vect[2][0] * hello.z); float b = (vect[0][1] * hello.x) + (vect[1][1] * hello.y) + (vect[2][1] * hello.z); float c = (vect[0][2] * hello.x) + (vect[1][2] * hello.y) + (vect[2][2] * hello.z); return CVector3(a,b,c); } Or am i going about it wrong and should somehow be rotating the hole cube ?

Share this post


Link to post
Share on other sites
Advertisement
Probably coding bugs. Post complete code.
You should transform ALL your CORNER points using matrix.
Also,
Quote:

cubeSide1 = matrixMultiplication(xrotate,cubeSide1);

not a good idea.
Keep original cube, and each time make new rotation matrix for your angle, just with bigger angle. Even correct rotation isn't perfect, especially with floats, and if you many times consequently rotate something, you'll get bad results.

Share this post


Link to post
Share on other sites
Why use 24 points to represent your cube when most of these are degenerate. A cube can be fully described with just 8 unique points, the corners of the cube. Are you always remembering to rotate your cube around the origin before applying any transformations?

Share this post


Link to post
Share on other sites
Quote:
Original post by Godden
it doesnt rotate at all it seems to stretch thur the sides of it

i think i know what your problem is.

are you by any chance storing your result in you input without a temp vector?

youll need to do:

temp = matrix* vector
return temp;

this will produce the result you are describgin:

vector = matrix * vector
return vector;

Share this post


Link to post
Share on other sites
sorry i was in a hurry there.

so what you shouldnt do is:


vector multiply(vector v){
v.x = v.x*matrix + v.y*matrix+v.z*matrix;
v.y = v.x*matrix + v.y*matrix+v.z*matrix;
v.z = v.x*matrix + v.y*matrix+v.z*matrix;
return v;
}


what you should do is:

vector multiply(vector v){
vector temp
temp.x = v.x*matrix + v.y*matrix+v.z*matrix;
temp.y = v.x*matrix + v.y*matrix+v.z*matrix;
temp.z = v.x*matrix + v.y*matrix+v.z*matrix;
return temp;
}

look closely and im sure youll see why.

if this wasnt the problem, consider this not posted :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Motorherp
Why use 24 points to represent your cube when most of these are degenerate. A cube can be fully described with just 8 unique points, the corners of the cube. Are you always remembering to rotate your cube around the origin before applying any transformations?



how would i go about that ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Godden
Quote:
Original post by Motorherp
Why use 24 points to represent your cube when most of these are degenerate. A cube can be fully described with just 8 unique points, the corners of the cube. Are you always remembering to rotate your cube around the origin before applying any transformations?

how would i go about that ?

Store the 8 corner verts in an array and have each face contain offsets into this array to the verts it encompases. This way you only need to tranform 8 verts instead of 24. As for the order of transformations, always rotate first then translate in this situation otherwise the rotation will also move the objects centre position which isn't what you want. If you're doing this the wrong way around though it shouldn't make your object warp and I think Eelco's on the nail with this. What he's saying is that you need a temp vert to work with whilst rotating. If you write directly in to the same vert, the result of them writings will distort the rest of your calculations since you'll be continuing your rotation maths with a vector that has some coords already rotated and some not.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!