Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (606) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 pointAt  (Read 985 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

You cannot reply to this message, because it is very, very old.

 theagentd (11 views) 2015-03-27 23:08:20 wxwsk8er (52 views) 2015-03-20 15:39:46 Fairy Tailz (46 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (38 views) 2015-03-13 17:50:16 Olo (44 views) 2015-03-13 17:47:07 ClaasJG (57 views) 2015-03-10 11:36:42 ClaasJG (41 views) 2015-03-10 11:33:01 Pippogeek (47 views) 2015-03-05 14:36:23
 LiquidNitrogen 21x BurntPizza 21x basil_ 20x KevinWorkman 18x EgonOlsen 17x Roquen 16x theagentd 16x 65K 11x Riven 10x wessles 10x princec 10x Varkas 10x Ashedragon 8x phu004 8x SHC 8x lcass 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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