Can someone give me an example of how I can get a point halfway between 2 points.
Thanks
Getting a vector3df halfway between 2 vector3df's
There are a few ways. Assuming you have the two points as vectors...
Code: Select all
core::vector3df p1(0, 0, 0);
core::vector3df p2(10, 10, 10);
// use linear interpolation to find halfway point
core::vector3df p3 = p1.getInterpolated(p2, .5f);
// add half of the distance between the two points
// to the first point. i.e. get vector from p1 to p2,
// cut it in half, and then add that to p1.
core::vector3df p4 = p1 + ((p2 - p1) * .5f);
Just out of curiosity, why not do it like this?vitek wrote:Code: Select all
core::vector3df p1(0, 0, 0); core::vector3df p2(10, 10, 10); // add half of the distance between the two points // to the first point. i.e. get vector from p1 to p2, // cut it in half, and then add that to p1. core::vector3df p4 = p1 + ((p2 - p1) * .5f);
Code: Select all
core::vector3df p4 = ((p2+p1) * .5f);
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
Works equally poorly on all systems.
-- unknown
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
I think the nicest (and equally fast) method is
Code: Select all
core::vetor3df center = core::line3df(start,end).getMiddle();