Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 pointAt  (Read 1831 times) 0 Members and 1 Guest are viewing this topic.
aNt

Senior Devvie

AFK

 « Posted 2004-08-31 13:51:59 »

anyone got a pointAt bit of code? as in rotate object A to pointAt object B.

topsssss!!!
aNt

Senior Devvie

AFK

 « Reply #1 - Posted 2004-08-31 14:00:19 »

i made a pointAt in gl back in the days like this. not sure
if anyone want it

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);

would be cool to have one in Xith3d part of transform3d or transformGroup maybe?
LaLiLuLeLo

Senior Newbie

Foooocus!

 « Reply #2 - Posted 2004-08-31 14:05:09 »

aNt

Senior Devvie

AFK

 « Reply #3 - Posted 2004-08-31 14:10:12 »

i couldnt find it. anyone no where it is?
William Denniss

JGO Coder

Projects: 2

Fire at will

 « Reply #4 - Posted 2004-08-31 23:34:49 »

Transform3D.lookAt?

Will.

aNt

Senior Devvie

AFK

 « Reply #5 - Posted 2004-09-01 13:21:19 »

you have to give that eye, center, up...

mine; u give it a vector loaction of the pointing object and the location vector of the object ot point at- returns the angles to rotate. simpler. bish bosh...
William Denniss

JGO Coder

Projects: 2

Fire at will

 « Reply #6 - Posted 2004-09-01 21:31:57 »

"vector loaction of the pointing object"  - the 'eye'
"the location vector of the object ot point at" - the 'center of view'
Vector pointing up, usually (0,1,0) for Y is up.

I don't see the difference

Will.

Pages: [1]
 ignore  |  Print

 DesertCoockie (33 views) 2018-05-13 18:23:11 nelsongames (75 views) 2018-04-24 18:15:36 nelsongames (70 views) 2018-04-24 18:14:32 ivj94 (752 views) 2018-03-24 14:47:39 ivj94 (82 views) 2018-03-24 14:46:31 ivj94 (622 views) 2018-03-24 14:43:53 Solater (98 views) 2018-03-17 05:04:08 nelsongames (179 views) 2018-03-05 17:56:34 Gornova (405 views) 2018-03-02 22:15:33 buddyBro (1065 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org