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  
  Fixing x axis rotation  (Read 325 times)
0 Members and 1 Guest are viewing this topic.
Offline lcass
« Posted 2013-11-08 22:58:03 »

Ive been getting an issue with the code below, there is no issue with the rotation around the y axis but when I try to rotate around the x axis it doesnt act properly ie the values dont change accordingly they compress up into a cluster at the town of the screen when I increase the xrot value.
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  
public void drawline(int x, int y, int xx, int yy) {

      double grad = Math.atan2(xx - x, yy - y);
      double cx = x;
      double cy = y;
      double dist = Math.sqrt((Math.abs(xx - x)) * (Math.abs(xx - x))
            + (Math.abs(yy - y)) * (Math.abs(yy - y)));
      double nx = Math.sin(grad);
      double ny = Math.cos(grad);
      for (int i = 0; i < dist; i++) {
         cx = (i*nx)+x;
         cy = (i*ny)+y;
         if (cx < core.WIDTH && cy < core.HEIGHT) {
            if (cx > 0 && cy > 0) {
               core.screen.map[(int) cx][(int) cy] = 0xFF00FF;
            }
         }
      }

   }

   public void drawnet(vertex v1, vertex v2, vertex v3, vertex v4, Camera c) {
      vertex[] v = new vertex[4];
      Positionalobject[] po = new Positionalobject[4];
      for (int i = 0; i < 4; i++) {
         po[i] = new Positionalobject();
      }
      v[0] = v1;
      v[1] = v2;
      v[2] = v3;
      v[3] = v4;
      for (int i = 0; i < 4; i++) {
         double tx = v[i].x - c.x;
         double ty = v[i].y - c.y;
         double tz = v[i].z - c.z;
         if (tz < 500) {
            double sinex = Math.sin(c.rotx);
            double cosx = Math.cos(c.rotx);
            double cosy = Math.cos(c.roty);
            double siny = Math.sin(c.roty);
            double dx = 0;
            double my = 0;
            double mz = 0;
            double dz = 0;
            dx = tz * siny + tx * cosy;
            dz = tz * cosy - tx * siny;
            my = ty * cosx - dz * sinex;
            mz = dz * sinex + dz * cosx;
           
            double nx = (dx) * (scalex / mz) + (core.WIDTH / 2);
            double ny = (my) * (scaley / mz) + (core.HEIGHT / 2);
            nx = (scalex * dx / mz) + (core.WIDTH / 2);
            ny = (scaley * my / mz) + (core.HEIGHT / 2);
            double mmz = ((mz-c.z)+(nx-c.x));
            po[i].x = nx;
            po[i].y = ny;
            po[i].z = mmz;
         
         }

      }
      if (po[0].x < core.WIDTH && po[0].y < core.HEIGHT && po[0].x > 0
            && po[0].y > 0) {
         drawline((int) po[0].x, (int) po[0].y, (int) po[1].x, (int) po[1].y);
         drawline((int) po[1].x, (int) po[1].y, (int) po[2].x, (int) po[2].y);
         drawline((int) po[2].x, (int) po[2].y, (int) po[3].x, (int) po[3].y);
         drawline((int) po[3].x, (int) po[3].y, (int) po[0].x, (int) po[0].y);
      }
   }
Offline lcass
« Reply #1 - Posted 2013-11-11 15:11:19 »

dx = tz * siny + tx * cosy;
dz = tz * cosy - tx * siny;
my = ty * cosx - dz * sinex;
mz = dz * sinex + dz * cosx;
is the specific area of the problem
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.

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

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

moogie (19 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 (45 views)
2014-09-12 09:08:26

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

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

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
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!