# Transform Vertex Coord: How?

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

## Recommended Posts

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?

##### Share on other sites
Both of your examples seem correct; what kind of 'unexpected results' do they produce?

##### Share on other sites
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?

##### Share on other sites
You cannot translate 3d vectors with matrices. You have to use 4d vectors with the 4:th component = 1 (homogeneous coordinates).

##### Share on other sites
Oh. Code solved. it just forgot to add the last parameter to y and z values :D

Thank you very much for your help!

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
17
5. 5

• 33
• 13
• 12
• 10
• 12
• ### Forum Statistics

• Total Topics
632573
• Total Posts
3007140

×