Elevation done :)
Elevation done :)
- Subject: Elevation done :)
- From: aNt <email@hidden>
- Date: Mon, 06 Jan 2003 14:18:12 +0000
Here it is if anyone wants it :) it was more of a learning process for me.
But someone my find this of some help and clear up some pain.
Thanks to everyone one who emailed me.. Brian. Joshua, Seth, Dmitry, Todd,
Werner more of Brian and everyone else :). All your input got me there in
the end.. I bet u are all going to email me saying there's a faster way
using the dot product :)... One step at a time... But u would love to no.
Here it is:
// returns the distance between two 3d points in space.
public static float getDistance(Vector4 pnt1, Vector4 pnt2) {
double dx = pnt2.x - pnt1.x;
double dy = pnt2.y - pnt1.y;
double dz = pnt2.z - pnt1.z;
return((float)Math.sqrt(dx*dx + dy*dy + dz*dz));
}
// convert x, y location to an angle - azimuth
public static float getAzimuth(Vector4 pnt1, Vector4 pnt2) {
float x = -(pnt1.x - pnt2.x);
float z = -(pnt1.z - pnt2.z);
float rangle = (float)(Math.atan2(x, z));
return(180.0f * rangle / 3.14159f);
}
// convert x, y, z location to an angle - elevation
public static float getElevation(Vector4 pnt1, Vector4 pnt2) {
float y = (pnt1.y - pnt2.y);
float x = (pnt1.x - pnt2.x);
float z = (pnt1.z - pnt2.z);
float d = (float)Math.sqrt(z*z + x*x);
if(d == 0) d = 0.0001f; // just in case we get a zero distance
float ang = (float)Math.atan(y / d);
return((float)Math.toDegrees(ang));
}
If u want the gl bit:
Vector4 v1 = new Vector4(0f, 0f, 0f);
Vector4 v2 = new Vector4(10f, 5f, -20); // whatever.
float azimuth = Utils.getAzimuth(v1, v2);
float elevation = Utils.getElevation(v1, v2);
float distance = Utils.getDistanceZX(v1, v2);
gl.glRotatef(azimuth, 0f, 1f, 0f);
gl.glRotatef(elevation, 1f, 0f, 0f);
Thanks again and it all seems so simple now :) triangles mad stuff.
Tops
aNt
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.