Transform Vertex Coord: How?

Started by
3 comments, last by Kasya 14 years ago
Hello, I want to transform my vertex coordinates into a specific position (e.g from (0,0,0) to (5, 0, 5) ). I did like that (which doesn't give the needed results): verts.x += pos.x; verts.y += pos.y; verts.z += pos.z; i tried to use matrices. No luck:


transform.Identity();
transform.Translate(pos);

for(int i = 0; i < numVerts; ++i) {
Vector3 newpos = transform.TransformVector(Vector3(verts.x, verts.y, verts.z));

verts.x = newpos.x;
verts.y = newpos.y;
verts.z = newpos.z;

}


this gives quite unexpected results. How can i do?
Advertisement
Both of your examples seem correct; what kind of 'unexpected results' do they produce?
in my app, the pos value is set to Vec3(5,0,8). With matrices the 1st vertex (haven't watched others) translated from Vec3(1,2,-1) to Vec3(2,2,-1). But with just adding positions (the 1st one) it is translated to Vec3(6,2,7). after thinking a little bit about that i think the Vec3(6,2,7) is correct because its just one vertex of a cube. What do you think? Am i thinking correctly?
You cannot translate 3d vectors with matrices. You have to use 4d vectors with the 4:th component = 1 (homogeneous coordinates).

Emil Jonssonvild
Oh. Code solved. it just forgot to add the last parameter to y and z values :D

Thank you very much for your help!

This topic is closed to new replies.

Advertisement