Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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 986 times)
0 Members and 1 Guest are viewing this topic.
Offline SkyAphid
« Posted 2012-06-18 19: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?

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline CyanPrime
« Reply #1 - Posted 2012-06-18 19:29:35 »

1  
2  
3  
glTranslate(-cube.pos);
glRotate(your angle, your axis);
glTranslate(cube.pos);
Offline SkyAphid
« Reply #2 - Posted 2012-06-18 21: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!

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-06-18 21: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 21: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..

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
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.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!