• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
too_many_stars

openGL, rotation, collision

7 posts in this topic

Hi Guys,

 

Have a bit a canudrum. I have lines made up of a vector called 'start' and 'end'

These lines are in an array which form a rectangle, which is then rotated about the center of the screen thus...

void showLine(){
		glLoadIdentity();
		glTranslatef(SCREEN_WIDTH/2,SCREEN_WIDTH/2,0.0f);
		glRotatef(rot,0.0f,0.0f,1.0f);
		glTranslatef(-SCREEN_WIDTH/2,-SCREEN_WIDTH/2,0.0f);
		glBegin(GL_LINES);
			glColor3f(1.0f,0.5f,0.3f);
			glVertex2f(start.x,start.y);
			glVertex2f(end.x,end.y);
			
		glEnd();
	
	}//this is only one line segment

I have a collision function (line segment vs circle) all figured out, but as I loop through the simulation, i am not sure how to update my two line vectors, start.x, start.y, end.x, end.y with GL's rotation algorithm. I need to find some kind of relationship.

 

If you know how to solve this problem please let me know.

 

Thanks,
 

Mike

0

Share this post


Link to post
Share on other sites

You need to multiply the line points with the rotation matrix. You can get the current matrix with glGetFloatv and store it into an array. I'm not quite sure how to get only the rotation matrix but you could try storing the current matrix and calling glLoadIdentity before the rotation (resets the matrix). If you know the angle you could easily do this using basic math, without gl.

Edited by ilreh
0

Share this post


Link to post
Share on other sites
Your ordering of translations and rotations is not only wrong, but extremely strange.
Why are you doing the second translate? It serves only the purpose of ensuring most of the time you won’t see anything (which seems to be your problem).

Load identity and then stop messing with translations and rotations (leave it as identity).
Put the line points where you actually want them in screen coordinates.

Ensure you have prepared a projection matrix of the orthogonal kind.


L. Spiro
0

Share this post


Link to post
Share on other sites

Hi Spiro,

 

For some arbitrary center of rotation, with arbitrary number of lines in an object doing the rotating, I don't know how to figure out where the points are supposed to be, unless I use cosx, siny for a unit circle type of scenario.

 

Let's say I have an asteroid with 50 points, that's a lot of resources it seems to figure out for each iteration where 49 lines are. My question is can I use glRotation (since it is already crunching all the numbers and knows where every pixel is located) to figure out my: start.x,start.y,end.x,end.y for all lines in an object.

 

You will have to pardon me if the above code example is wrong, I have looked on line and that's what appears to be the common method. I am also very new to openGL 2.x

 

Thanks,

 

Mike

0

Share this post


Link to post
Share on other sites
If all the points are around the origin if the object and you are drawing something like Asteroids, rotate first, then translate. Once.

 
	void showLine(){
		glLoadIdentity();
		glRotatef(0.0f,0.0f,rot);				// glRotatef() has 3 parameters.  Rotate around Z.
		glTranslatef(SCREEN_WIDTH/2,SCREEN_WIDTH/2,0.0f);	// Then move to the center of the screen.

		// Or move to the position of the object relative to the center of the screen.
		//glTranslatef(SCREEN_WIDTH/2+objPos.x,SCREEN_WIDTH/2+objPos.x,0.0f);

		glBegin(GL_LINES);
			glColor3f(1.0f,0.5f,0.3f);
			glVertex2f(start.x,start.y);
			glVertex2f(end.x,end.y);
			
		glEnd();
	
	}//this is only one line segment
 

I have looked on line and that's what appears to be the common method.

It was common perhaps 20 years ago. It’s outdated and deprecated, meaning no longer supported and not the common way anymore.


L. Spiro Edited by L. Spiro
0

Share this post


Link to post
Share on other sites

If all the points are around the origin if the object and you are drawing something like Asteroids, rotate first, then translate. Once.

 

	void showLine(){
		glLoadIdentity();
		glRotatef(0.0f,0.0f,rot);				// glRotatef() has 3 parameters.  Rotate around Z.
		glTranslatef(SCREEN_WIDTH/2,SCREEN_WIDTH/2,0.0f);	// Then move to the center of the screen.

		// Or move to the position of the object relative to the center of the screen.
		//glTranslatef(SCREEN_WIDTH/2+objPos.x,SCREEN_WIDTH/2+objPos.x,0.0f);

		glBegin(GL_LINES);
			glColor3f(1.0f,0.5f,0.3f);
			glVertex2f(start.x,start.y);
			glVertex2f(end.x,end.y);
			
		glEnd();
	
	}//this is only one line segment
 

I have looked on line and that's what appears to be the common method.

It was common perhaps 20 years ago. It’s outdated and deprecated, meaning no longer supported and not the common way anymore.


L. Spiro

 

 

 

Spiro, the original code was correct. You might not like what he's doing, but he is simply changing a pivot. That is a standard approach, the runtime cost is negligible, and whilst it might not be something I'd recommend, it isn't actually wrong at all. The original code is also using glRotatef correctly (it does not take 3 parameters - it takes 4 - The angle, and the axis. Any rotate function that takes 3 args, is a gimbal-locking function best avoided!).

 

Let's say I have an asteroid with 50 points, that's a lot of resources it seems to figure out for each iteration where 49 lines are. My question is can I use glRotation (since it is already crunching all the numbers and knows where every pixel is located) to figure out my: start.x,start.y,end.x,end.y for all lines in an object.

 

You won't be able to use glRotate, but you can use a matrix to transform the points instead. (it might be worth computing your own transforms, and glMultMatrix instead of glRotatef/glTranslatef). CPU's are faster than you think, so there should be no significant performance problem in doing that. Just be aware that if you want to port you code to GL3+ at any point, you'll need to do your own matrix calculations anyway. You might as well start now - it'll be less hassle in the future. 

0

Share this post


Link to post
Share on other sites

Thanks for the advice guys, I have revamped my code to make it cleaner and working on the point transforms right now.

 

Before I started working with openGL 2.x I knew that it's outdated. However, a number of people recommended to start with 2.x (as it's easier than 3+) to get used to the 3d co-ordinates so I chose that as my immersion.

 

Thanks,

 

Mike

0

Share this post


Link to post
Share on other sites

Spiro, the original code was correct. You might not like what he's doing, but he is simply changing a pivot.

He is changing the pivot to the center of the screen. It’s not correct. If the object’s pivot was not [0, 0], yes, translate by negative pivot (which is another problem in his original code), but the negative center of the screen (the pivot point derived from his positive half-screen translations) is very very unlikely to be the pivot point.
This is what I meant when I said it ensures most of the time he won’t see anything. Object starts at lower-left, moves to the center of the screen, spins around the [0, 0] origin (making a wide circular sweep), and the moves back to the [0, 0] origin, making it 75%-of-the-time off the screen to the left, bottom, or bottom-left.


The original code is also using glRotatef correctly

I misread the prototype. So on this point his original code is correct.


L. Spiro
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0