Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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 874 times)
0 Members and 1 Guest are viewing this topic.
Offline aNt

Senior Member




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!!!
Offline aNt

Senior Member




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 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 14: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 14: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-08-31 23:34:49 »

Transform3D.lookAt?

Will.

Offline aNt

Senior Member




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...
Offline 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  Huh

Will.

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

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (9 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (46 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
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!