Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  airplane matrix problem  (Read 2391 times)
0 Members and 1 Guest are viewing this topic.
Offline Therion__

Junior Member





« Posted 2008-06-11 13:31:57 »

hello,

i dont know where to search...
i got an airplane sim, camera with 3 angles
(yaw,pitch and roll)
and i simple search for the "pull the stick back" formula

every try failed.
my last idea was to get the matrix of camera.adding a vector
(0,1,10) -> as the new rotation point..and recalculate
yaw and pitch from that.. only an error...

the camera works..only the rotation to the new orientation failed

can anybody help me?
Offline bahuman

Junior Member





« Reply #1 - Posted 2008-06-12 09:23:07 »

http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

If you keep track of yaw, pitch and roll at the same type, you may be running into the famous gridlock problem (google it).

What I usually do for an airplane: I represent it with 3 unit vectors ("forward", "up", and "right"). For rolls, I rotate the "up" and "right" vectors around the "forward" vector. Pitch and yaw are similar: you take one vector, and you rotate the other 2 around it.
Offline Therion__

Junior Member





« Reply #2 - Posted 2008-06-12 21:09:56 »

i understand the problem, the gridlock is my problem

i dont have an idea/strategy how to implement
this 3 verctor thing to my game

at moment it works all with

 gl.glMatrixMode(GL.GL_MODELVIEW);
     gl.glLoadIdentity();        
     gl.glRotatef(-vr3, 0, 0, 1); //roll
     gl.glRotatef(-vr2, 1, 0, 0); //pitch
     gl.glRotatef(-vr1, 0, 1, 0); //yaw

but i dont have any idea how to change it that
i get a correct rotation of the aircraft in direction(roll)


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #3 - Posted 2008-06-12 21:29:10 »

A simple way to avoid gimblelock is to re-compute back your three rotations rx,ry,rz after having performed local axis (the 3 units vectors) rotation.


for each move/frames do

1 - Init the local axis
vx=(1,0,0)
vy=(0,1,0)
vz=(0,0,1)

than you set its values using currents object(plane for you) rotations : rx,ry,rz

=>> here you can easily rotate in "Object Space" : around any of the three axis vx,vy,vz as "pull the stick back" fo example : vx*RY , vy*RY, vz*RY

2 - Rotate the local Axis

vx2=vx*RX(rx)*RY(ry)*RZ(rz)
vy2=vy*RX(rx)*RY(ry)*RZ(rz)
vz2=vz*RX(rx)*RY(ry)*RZ(rz)

=>> here your can rotate about any arbitrary axis in "World space"

3 - Compute back current rotation and store them in rx,ry,rz

rx=computeRX(vx,vy,vz)
ry=computeRY(vx,vy,vz)
rz=computeRZ(vx,vy,vz)

Not sure I was clear... I will try to make a longer answer later



Offline Therion__

Junior Member





« Reply #4 - Posted 2008-06-12 22:19:14 »

its a hard thing..

i tryed to search the whole google
for formulas or something that i understand .

my biggest problem is that english is not my
primary language.

ok: vx,vy and vz are vectors and easy to initalise

rx,ry and rz are also vectory or rotation values(degrees)??

what is the difference between RX and rx in your example?

and vx2,vy2,vz2 are also vectors?

i am very confused 

 
Offline DzzD
« Reply #5 - Posted 2008-06-14 08:00:34 »

the whole 3dzzd axis class, messy Smiley

getRotationXZY
return the XZY rotation applied to the given axis as a piont3d/vector.
returned value in this point3d (x,y,z) are angle of rotation around axis x,y,z in the order XZY.

if you need more let me know (mmay be the pooint3d class will help you ? ), cant post code larger than 10000 character that's boring

EDIT: cleaned class code below

Offline Therion__

Junior Member





« Reply #6 - Posted 2008-06-15 09:23:54 »

much much thx DzzD Smiley

i will study the code and learn to understand the working Smiley

much thx again
Offline DzzD
« Reply #7 - Posted 2008-06-15 17:50:01 »

you welcome,

if it can help here a little more informtions:
IAxis3D == Axis3D => just replace all IAxis by Axis
IPoint3D == Point3D

Point3D is a simple class with double x,y,z components and some usefull methods for 3D on a point, it also need some cleaning but methods are so little than I guess they should be easily understandable.

EDIT: cleaned class code below

Offline DzzD
« Reply #8 - Posted 2008-06-17 03:12:55 »

cleaned 3DzzD Axis3D class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
414  
415  
416  
417  
418  
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  
package net.dzzd.core;

import net.dzzd.access.*;

/**
 *  A class representing 3D axis
 *  @version 1.0
 *  @since 1.0
 *  @see Point3D
 *  @author Bruno Augier
 *
 *  Copyright Bruno Augier 2005
 */


public final class Axis3D implements IAxis3D
{
   Point3D origine;   //Origin
  Point3D axeX;      //Axis x
  Point3D axeY;      //Axis y
  Point3D axeZ;      //Axis z
 
   public Axis3D()
   {
      this.origine=new Point3D();
      this.axeX=new Point3D();  
      this.axeY=new Point3D();  
      this.axeZ=new Point3D();  
      this.init();
   }
     
   IAxis3D normalize()
   {
      this.axeX.sub(this.origine).normalize().add(this.origine);
      this.axeY.sub(this.origine).normalize().add(this.origine);
      this.axeZ.sub(this.origine).normalize().add(this.origine);                  
      return this;        
   }  


   IAxis3D set(IPoint3D position)
   {      
      this.add(position.getX(),position.getY(),position.getZ());
      return this;        
   }

   IAxis3D getPosition(IPoint3D position)
   {
      position.setX(this.origine.x);
      position.setY(this.origine.y);
      position.setZ(this.origine.z);
      return this;
   }
   

               
   
   /** Transform this axis values into the local axis a
    *  @param a an axis to transform axis to
     *  @return same axis "viewed" by axis a
     */
                                                     
   IAxis3D toLocalAxe(IAxis3D a)
   {
      IPoint3D p;
      IPoint3D o=a.getOrigin();      
      IPoint3D ax=a.getAX();
      IPoint3D ay=a.getAY();
      IPoint3D az=a.getAZ();  
      double ox=o.getX();      
      double oy=o.getY();
      double oz=o.getZ();
      double axx=ax.getX()-ox;      
      double axy=ax.getY()-oy;
      double axz=ax.getZ()-oz;
      double ayx=ay.getX()-ox;      
      double ayy=ay.getY()-oy;
      double ayz=ay.getZ()-oz;        
      double azx=az.getX()-ox;      
      double azy=az.getY()-oy;
      double azz=az.getZ()-oz;  
     
      p=this.getOrigin();
      double x=p.getX()-ox;
      double y=p.getY()-oy;
      double z=p.getZ()-oz;        
      p.setX(axx*x+axy*y+axz*z);
      p.setY(ayx*x+ayy*y+ayz*z);
      p.setZ(azx*x+azy*y+azz*z);
           
      p=this.getAX();
      x=p.getX()-ox;
      y=p.getY()-oy;
      z=p.getZ()-oz;        
      p.setX(axx*x+axy*y+axz*z);
      p.setY(ayx*x+ayy*y+ayz*z);
      p.setZ(azx*x+azy*y+azz*z);
         
      p=this.getAY();
      x=p.getX()-ox;
      y=p.getY()-oy;
      z=p.getZ()-oz;        
      p.setX(axx*x+axy*y+axz*z);
      p.setY(ayx*x+ayy*y+ayz*z);
      p.setZ(azx*x+azy*y+azz*z);
     
      p=this.getAZ();
      x=p.getX()-ox;
      y=p.getY()-oy;
      z=p.getZ()-oz;        
      p.setX(axx*x+axy*y+axz*z);
      p.setY(ayx*x+ayy*y+ayz*z);
      p.setZ(azx*x+azy*y+azz*z);
     
      return this;
   }
   
   /** Put this axis in the given axis space
    *  @param a an axis to transform to its space
     *  @return same axis in axis parameter space
     */
                                                     
   IAxis3D toAxe(IAxis3D a)
   {
      IPoint3D p;
      IPoint3D o=a.getOrigin();      
      IPoint3D ax=a.getAX();
      IPoint3D ay=a.getAY();
      IPoint3D az=a.getAZ();  
      double ox=o.getX();      
      double oy=o.getY();
      double oz=o.getZ();
      double axx=ax.getX()-ox;      
      double axy=ax.getY()-oy;
      double axz=ax.getZ()-oz;
      double ayx=ay.getX()-ox;      
      double ayy=ay.getY()-oy;
      double ayz=ay.getZ()-oz;        
      double azx=az.getX()-ox;      
      double azy=az.getY()-oy;
      double azz=az.getZ()-oz;  
     
      p=this.getOrigin();
      double x=p.getX();
      double y=p.getY();
      double z=p.getZ();        
      p.setX(ox+axx*x+ayx*y+azx*z);
      p.setY(oy+axy*x+ayy*y+azy*z);
      p.setZ(oz+axz*x+ayz*y+azz*z);
           
      p=this.getAX();
      x=p.getX();
      y=p.getY();
      z=p.getZ();            
      p.setX(ox+axx*x+ayx*y+azx*z);
      p.setY(oy+axy*x+ayy*y+azy*z);
      p.setZ(oz+axz*x+ayz*y+azz*z);
           
      p=this.getAY();
      x=p.getX();
      y=p.getY();
      z=p.getZ();            
      p.setX(ox+axx*x+ayx*y+azx*z);
      p.setY(oy+axy*x+ayy*y+azy*z);
      p.setZ(oz+axz*x+ayz*y+azz*z);
           
      p=this.getAZ();
      x=p.getX();
      y=p.getY();
      z=p.getZ();            
      p.setX(ox+axx*x+ayx*y+azx*z);
      p.setY(oy+axy*x+ayy*y+azy*z);
      p.setZ(oz+axz*x+ayz*y+azz*z);
     
      return this;
   }      
   
   public IAxis3D init()
   {
      this.origine.set(0,0,0);
      this.axeX.set(1,0,0);  
      this.axeY.set(0,1,0);  
      this.axeZ.set(0,0,1);  
      return this;        
   }
   
   public IPoint3D getAX()
   {
      return this.axeX;
   }
   
   public IPoint3D getAY()
   {
      return this.axeY;
   }
   
   public IPoint3D getAZ()
   {
      return this.axeZ;
   }      
   
   public IPoint3D getOrigin()
   {
      return this.origine;
   }
     
   public IAxis3D copy(IAxis3D a)
   {
      this.origine.copy(a.getOrigin());
      this.axeX.copy(a.getAX());
      this.axeY.copy(a.getAY());
      this.axeZ.copy(a.getAZ());
      return this;
     
   }

   public IAxis3D add(double x,double y,double z)
   {
      this.origine.add(x,y,z);
      this.axeX.add(x,y,z);
      this.axeY.add(x,y,z);
      this.axeZ.add(x,y,z);
      return this;
   }

   public IAxis3D sub(double x,double y,double z)
   {
      return this.add(-x,-y,-z);
   }

   public IAxis3D add(IPoint3D point)
   {
      return this.add(point.getX(),point.getY(),point.getZ());
   }

   public IAxis3D sub(IPoint3D point)
   {
      return this.add(-point.getX(),-point.getY(),-point.getZ());
   }

   public IAxis3D rotateX(double angle)
   {
      this.origine.rotateX(angle);
      this.axeX.rotateX(angle);;
      this.axeY.rotateX(angle);
      this.axeZ.rotateX(angle);
      return this;
   }

   public IAxis3D rotateY(double angle)
   {
      this.origine.rotateY(angle);
      this.axeX.rotateY(angle);;
      this.axeY.rotateY(angle);
      this.axeZ.rotateY(angle);
      return this;
   }
   
   public IAxis3D rotateZ(double angle)
   {
      this.origine.rotateZ(angle);
      this.axeX.rotateZ(angle);;
      this.axeY.rotateZ(angle);
      this.axeZ.rotateZ(angle);
      return this;
   }

   public IAxis3D rotate(double angle,double px,double py,double pz,double x,double y,double z)
   {
      this.add(-px,-py,-pz);
      this.rotate(angle,x-px,y-py,z-pz);
      this.add(px,py,pz);
      return this;
   }

   public IAxis3D rotate(double angle,IPoint3D pivot,IPoint3D axis)
   {
      return this.rotate(angle,pivot.getX(),pivot.getY(),pivot.getZ(),axis.getX(),axis.getY(),axis.getZ());
   }

   public IAxis3D rotate(double angle,double px,double py,double pz,IPoint3D axis)
   {
      return this.rotate(angle,px,py,pz,axis.getX(),axis.getY(),axis.getZ());
   }

   public IAxis3D rotate(double angle,IPoint3D axis)
   {
      return this.rotate(angle,axis.getX(),axis.getY(),axis.getY());
   }
     
   public IAxis3D rotate(double angle,double x,double y,double z)
   {
     
      double n=Math.sqrt(x*x+y*y+z*z);
      if(n==0.0) return this;
      double in=1.0/n;
      x*=in;
      y*=in;
      z*=in;
     
      double nzx=Math.sqrt(x*x+z*z);
      //if(nzx==0.0) return this;
       
      double rx=Math.asin(y);
      double ry=0;
      if(nzx!=0.0)
      {
         ry=-Math.acos(z/nzx);
         if(x<0)
            ry=-ry;
      }
      else
      {   if(y>0)
            rx=Math.PI*0.5;
         else
            rx=-Math.PI*0.5;
         ry=0;
      }

      this.rotateY(-ry);
      this.rotateX(-rx);
      this.rotateZ(angle);
      this.rotateX(rx);
      this.rotateY(ry);
   
      return this;      
   }
   
   /** Past the rotation (rx,ry,rz) of this axis in the given point
    *  @param rotation a point to received this axis rotation (rx,ry,rz)
     *  @return the same axis
     */
             
   IAxis3D getRotationXYZ(IPoint3D rotation)
   {
      this.getRotationXZY(rotation);
      double rz=rotation.getY();
      rotation.setY(rotation.getZ());
      rotation.setZ(rz);
      return this;
   }
     
   public IAxis3D getRotationXZY(IPoint3D rotation)
   {
      Point3D o=this.origine;      
      Point3D ax=this.axeX;
      Point3D ay=this.axeY;
      Point3D az=this.axeZ;            
      double ox=o.x;      
      double oy=o.y;
      double oz=o.z;
      double axx=ax.x-ox;      
      double axy=ax.y-oy;
      double axz=ax.z-oz;
      double ayx=ay.x-ox;      
      double ayy=ay.y-oy;
      double ayz=ay.z-oz;        
      double azx=az.x-ox;      
      double azy=az.y-oy;
      double azz=az.z-oz;
           
     
      double den=Math.sqrt((axx*axx)+(axy*axy)+(axz*axz));
      double sz=-axy/den;
     
           
      double rz=0.0;
      if(sz>1.0) sz=1.0;
      if(sz<-1.0) sz=-1.0;
         rz=Math.asin(sz);
             
      den=Math.sqrt((axx*axx)+(axz*axz));
      if(den>1.0) den=1.0;
      double rx=0.0;
      double ry=0.0;
      if(Math.abs(den)>0.0);//Double.MIN_VALUE*10)
     {
         double cx=ayy/den;        
         if(cx>1.0) cx=1.0;
         if(cx<-1.0) cx=-1.0;
         rx=Math.acos(cx);
         if(azy<0.0)
          rx=-rx;
                   
   
         double cy=axx/den;        
         if(cy>1.0) cy=1.0;
         if(cy<-1.0) cy=-1.0;              
         ry=Math.acos(cy);
         if(axz<0.0)
          ry=-ry;
      }
     
      if(Math.abs(rx)>Math.PI*0.5 && Math.abs(ry)>Math.PI*0.5)
      {
         rx=-Math.PI+rx;
         ry=-Math.PI+ry;
         rz=Math.PI-rz;
      }
     
      rotation.set(rx,ry,rz);
      return this;      
   }

   public IAxis3D set(IPoint3D ipivot,IPoint3D iposition,IPoint3D irotation)
   {
      Point3D pivot=(Point3D)ipivot;
      Point3D position=(Point3D)iposition;
      Point3D rotation=(Point3D)irotation;
     
      this.add(-pivot.x,-pivot.y,-pivot.z);      
     
      this.rotateX(rotation.x);
      this.rotateZ(rotation.z);
      this.rotateY(rotation.y);      
      this.add(position.x,position.y,position.z);
      return this;        
   }

   public IAxis3D set(IPoint3D iposition,IPoint3D irotation)
   {
      Point3D position=(Point3D)iposition;
      Point3D rotation=(Point3D)irotation;            
     
      this.rotateX(rotation.x);      
      this.rotateZ(rotation.z);
      this.rotateY(rotation.y);      
      this.add(position.x,position.y,position.z);
      return this;        
   }

   
   
}

Offline DzzD
« Reply #9 - Posted 2008-06-17 03:13:42 »

cleaned 3DzzD Point3D class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
package net.dzzd.core;

import net.dzzd.access.*;
import net.dzzd.utils.*;

/**
 *  A class representing a 3D point x,y,z
 *  @version 1.0
 *  @since 1.0
 *  @see Vertex3D
 *  @author Bruno Augier
 *
 *  Copyright Bruno Augier 2005
 */

 
public class Point3D implements IPoint3D
{
   public double x,y,z;  
   
   public Point3D ()
   {
      this.set(0,0,0);  
   }
     
   public Point3D (double x,double y,double z)
   {
      this.set(x,y,z);
   }
   
   public void set(double x,double y,double z)
   {
      this.x=x;  
      this.y=y;
      this.z=z;
   }

   /** Rotate the point around the x axis
    *  @param angle radian angle for the rotation
     *  @return the same point rotated
     */

   public IPoint3D rotateX(double angle)
   {
      double tY=y,tZ=z;
      double cosa=MathX.cos(angle);
      double sina=MathX.sin(angle);
      y=tY*cosa + tZ*sina;
      z=-tY*sina + tZ*cosa;
      return this;
   }
   
   /** Rotate the point around the y axis
    *  @param angle radian angle for the rotation
     *  @return the same point rotated
     */
 
   public IPoint3D rotateY(double angle)
   {
      double tX=x,tZ=z;
      double cosa=MathX.cos(angle);
      double sina=MathX.sin(angle);
      x=tX*cosa - tZ*sina;
      z=tX*sina + tZ*cosa;
      return this;
   }
   
   /** Rotate the point around the z axis
    *  @param angle radian angle for the rotation
     *  @return the same point rotated
     */
 
   public IPoint3D rotateZ(double angle)
   {
      double tY=y,tX=x;
      double cosa=MathX.cos(angle);
      double sina=MathX.sin(angle);
      x=tX*cosa + tY*sina;
      y=-tX*sina + tY*cosa;
      return this;
   }
   
   public IPoint3D add(double x,double y,double z)
   {
      this.x+=x;  
      this.y+=y;
      this.z+=z;
      return this;
     
   }
   
   public IPoint3D cross(IPoint3D p)
   {
      double tX,tY,tZ;
      double x=p.getX();
      double y=p.getY();
      double z=p.getZ();
      tZ=this.x*y-this.y*x;
      tY=this.z*x-this.x*z;
      tX=this.y*z-this.z*y;
      this.x=tX;
      this.y=tY;
      this.z=tZ;      
      return this;      
   }
   
   public double dot(IPoint3D p2)
   {
      return this.x*p2.getX()+this.y*p2.getY()+this.z*p2.getZ();
   }
     
   public double norm()
   {
      return Math.sqrt(x*x+y*y+z*z);
   }

   public boolean equals(IPoint3D p)
   {
      if(this.x!=p.getX())   return false;
      if(this.y!=p.getY())   return false;
      if(this.z!=p.getZ())   return false;
      return true;
   }
   
   public IPoint3D mul(double n)
   {
      this.x*=n;
      this.y*=n;
      this.z*=n;
      return this;      
   }
   
   public IPoint3D div(double n)
   {
      double d=1.0/n;
      this.x*=d;
      this.y*=d;
      this.z*=d;
      return this;      
   }
     
   public double distance2(IPoint3D p)
   {
      double dx=this.x-p.getX();
      double dy=this.y-p.getY();
      double dz=this.z-p.getZ();
      return dx*dx+dy*dy+dz*dz;  
   }  
   
   public double dist(IPoint3D p)
   {
      return Math.sqrt(this.distance2(p));  
   }      
   
   public Point3D toLocalAxe(Axis3D a)
   {
      Point3D o=a.origine;      
      Point3D ax=a.axeX;
      Point3D ay=a.axeY;
      Point3D az=a.axeZ;  
      double ox=o.x;      
      double oy=o.y;
      double oz=o.z;
      double axx=ax.x-ox;      
      double axy=ax.y-oy;
      double axz=ax.z-oz;
      double ayx=ay.x-ox;      
      double ayy=ay.y-oy;
      double ayz=ay.z-oz;        
      double azx=az.x-ox;      
      double azy=az.y-oy;
      double azz=az.z-oz;  
      double x=this.x-ox;
      double y=this.y-oy;
      double z=this.z-oz;        
      this.x=axx*x+axy*y+axz*z;
      this.y=ayx*x+ayy*y+ayz*z;
      this.z=azx*x+azy*y+azz*z;        
      return this;
   }  
   
   public String toString()
   {
      return "(" + x + " , " + y + " , " + z + ")";
   }
   
   public double getX()
   {
      return this.x;
   }

   public double getY()
   {
      return this.y;
   }

   public double getZ()
   {
      return this.z;
   }
   
   public void setX(double val)
   {
      this.x=val;
   }

   public void setY(double val)
   {
      this.y=val;
   }

   public void setZ(double val)
   {
      this.z=val;
   }

   public IPoint3D copy(IPoint3D p)
   {
      this.x=p.getX();
      this.y=p.getY();
      this.z=p.getZ();  
      return this;
   }
                                       
   public IPoint3D add(IPoint3D p)
   {
      this.x+=p.getX();
      this.y+=p.getY();
      this.z+=p.getZ();  
      return this;
   }

   public IPoint3D sub(IPoint3D p)
   {
      this.x-=p.getX();
      this.y-=p.getY();
      this.z-=p.getZ();  
      return this;
   }

   public IPoint3D normalize()
   {
      double iLen=1.0/this.norm();
      this.x*=iLen;
      this.y*=iLen;
      this.z*=iLen;
      return this;
   }
   
   public IPoint3D zoom(double x,double y,double z)
   {
      this.x*=x;  
      this.y*=y;
      this.z*=z;
      return this;
   }
   
   public IPoint3D getClone()
   {
      return new Point3D(this.x,this.y,this.z);
   }  
}

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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

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

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

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

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

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

BurntPizza (54 views)
2014-09-19 03:14:18
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!