Jump to content
  • Advertisement
Sign in to follow this  
Kasya

Transform Vertex Coord: How?

This topic is 3160 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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!

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!