Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  pointAt  (Read 600 times)
0 Members and 1 Guest are viewing this topic.
Offline aNt

Senior Member




AFK


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

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

topsssss!!!
Offline aNt

Senior Member




AFK


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

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

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 Smiley part of transform3d or transformGroup maybe?
Offline LaLiLuLeLo

Senior Newbie




Foooocus!


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

doesn't xith3d already have this?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline aNt

Senior Member




AFK


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

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

JGO Coder


Projects: 2


Fire at will


« Reply #4 - Posted 2004-09-01 01:34:49 »

Transform3D.lookAt?

Will.

Offline aNt

Senior Member




AFK


« Reply #5 - Posted 2004-09-01 15: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...
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #6 - Posted 2004-09-01 23: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  Huh

Will.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (74 views)
2013-05-17 21:29:12

alaslipknot (86 views)
2013-05-16 21:24:48

gouessej (115 views)
2013-05-16 00:53:38

gouessej (110 views)
2013-05-16 00:17:58

theagentd (121 views)
2013-05-15 15:01:13

theagentd (110 views)
2013-05-15 15:00:54

StreetDoggy (155 views)
2013-05-14 15:56:26

kutucuk (177 views)
2013-05-12 17:10:36

kutucuk (174 views)
2013-05-12 15:36:09

UnluckyDevil (183 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.088 seconds with 21 queries.