Java-Gaming.org Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (612)
Games in Android Showcase (172)
games submitted by our members
Games in WIP (658)
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  
  Rotating a quad that isn't at the center of the grid..  (Read 1282 times)
0 Members and 1 Guest are viewing this topic.
Offline SkyAphid
« Posted 2012-06-18 17:11:50 »

First of all, sorry to make another post here so soon, I'm still new to this and I couldn't figure this out after at least 20 minutes of Googling.

So, I'm trying to rotate a quad that isn't at the center of a coordinate grid, like the title said.

This is what I initially tried:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void render(){
      int renderX = ot.getValue("fieldX") + (BattleRoom.FIELD_WIDTH * fieldX);
      int renderY = ot.getValue("fieldY") + (BattleRoom.FIELD_HEIGHT * fieldY);
      FloatBuffer matrix = BufferUtils.createFloatBuffer(16);
      glGetFloat(GL_MODELVIEW_MATRIX, matrix);
     
      glPushMatrix();
      //glTranslatef(renderX,renderY,0);
      //glRotatef(5, 0, 1, 0);
      glTranslatef(matrix.get(15), matrix.get(14), 0);
      glColor3f(1,1,1);
      currentAnim.render(renderX, renderY - 40);
      glPopMatrix();
   }


Basically I was getting the matrix values and placing them in a float buffer, and then pushing the matrix. I would then translate the grid so that the center was at the player, and then rotate, and move it back to its original position,draw him, and pop the matrix to ensure the rotation doesn't stick around. Unfortunately, the player is still nowhere to be found. In my debugging I noticed that if the commands that are noted out aren't there, the player draws correctly. So at least my matrix to float buffer idea worked Azn

Anyway, what should I do?

it just werks
Offline CyanPrime
« Reply #1 - Posted 2012-06-18 17:29:35 »

1  
2  
3  
glTranslate(-cube.pos);
glRotate(your angle, your axis);
glTranslate(cube.pos);
Offline SkyAphid
« Reply #2 - Posted 2012-06-18 19:10:56 »

1  
2  
3  
glTranslate(-cube.pos);
glRotate(your angle, your axis);
glTranslate(cube.pos);

That didn't solve my problem, unfortunately. Thanks anyway, though!

it just werks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 389
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-06-18 19:13:57 »

You don't need the matrix at all. What CyanPrime said was correct and should be the only code in that method.

Offline SkyAphid
« Reply #4 - Posted 2012-06-18 19:55:01 »

You don't the matrix at all. What CyanPrime said was correct and should be the only code in that method.
I can see where translating to a negative of where he was, and then rotating would work, but centering the translation back at where he is isn't, because it was never centered around him to begin with.

I only reference the old matrix so that I can recenter it at where it once was, so I can draw the player correctly in his place.

I mean, if this were built differently, I could see it working, but mine is really weird..

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

 
afikri (8 views)
2015-08-31 09:30:22

afikri (13 views)
2015-08-31 09:30:07

afikri (7 views)
2015-08-31 09:27:24

afikri (10 views)
2015-08-31 09:26:40

Roquen (16 views)
2015-08-29 11:30:54

GamerC4 (26 views)
2015-08-22 20:38:50

GamerC4 (24 views)
2015-08-22 20:37:18

GamerC4 (28 views)
2015-08-22 20:37:01

Kefwar (33 views)
2015-08-22 18:07:24

GamerC4 (26 views)
2015-08-22 01:00:24
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30
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!