Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / help manually roting vertices on: 2013-01-15 05:52:31
hi there guys, firstly id like to say hello to all as this is my first post here Cheesy

so i have just recently gotten into 3d development in java and so far i have picked up pretty fast, the hardest part was probably setting up my environment, but as i have programed in ruby for a while i picked up java pretty fast as it is object orientated, any way enough of that to the issue!

so i am currently trying to rotate vertices manually, i know i can use the glRotate method to achieve rotation, but this is so i can use logical functions later to detect collision etc, in this case i am constructing a box,i have managed to sort of apply the rotation manually, but it seems to go a little crazy, it rotates, but doesnt rotate to the right angle, so here is my code that manages the box and drawing of it:

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  
package com.game.base.uncatogorized.Graphics;

import static org.lwjgl.opengl.GL11.*;

public class Cube {

   public float xScale, yScale, zScale;
   
   public Cube(float xScale, float yScale, float zScale) {
     
      this.xScale = xScale;
      this.yScale = yScale;
      this.zScale = zScale;
     
   }
   
   public void draw(float x, float y, float z, float rotation) {
      float x1, y1, z1, rx, rz;
     
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glPushMatrix();
      {
         glTranslatef(0, 0, 0);
         glColor3f(1,0,0);  
         glBegin(GL_QUADS);
         {
           
            //FRONT FACE
            //BOTTOM LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
           
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //BOTTOM RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
           
            //RIGHT FACE
            //BOTTOM LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //BOTTOM RIGHT
            x1 = x - ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP RIGHT
            x1 = x - ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
           
            //BACK FACE
            //BOTTOM LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //BOTTOM RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
           
            //LEFT FACE
            //BOTTOM LEFT
            x1 = x + ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //BOTTOM RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP LEFT
            x1 = x + ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
           
            //TOP FACE
            //BOTTOM LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //BOTTOM RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y + ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
           
            //BOTTOM FACE
            //BOTTOM LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //BOTTOM RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z - ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP RIGHT
            x1 = x + ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
            //TOP LEFT
            x1 = x - ((1 * xScale) / 2);
            y1 = y - ((1 * yScale) / 2);
            z1 = z + ((1 * zScale) / 2);
            rx = (float) ((z1 * Math.sin(rotation)) + (x1 * Math.cos(rotation)));
            rz = (float) ((z1 * Math.cos(rotation)) - (x1 * Math.sin(rotation)));
            glVertex3f(rx, y1, rz);
         }
         glEnd();
         
      }
      glPopMatrix();
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      glColor3f(1,1,1);    
   }
   
}


i am currently only trying to rotate on the x and z, as you can see i am drawing the boxes in line mode, as that space will just represent impassable space, the reason i need it to rotate is so it rotates correctly with the object that it is bound around, ie. a character, then this box will act as the characters collider

also on the matter is this a good way to go about generating a collision area? i know about the physics library jbullet but that is a bit of an overhaul for what i require, anyway let me know if anyone knows how i can solve this Smiley

Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (31 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (26 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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