LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2012, 04:35 AM   #1
anon02
Member
 
Registered: Aug 2011
Posts: 223

Rep: Reputation: Disabled
Maps and Collision detection in OpenGL + C


I am currently writing a simple 3D game in OpenGL, while learning OpenGL. I was wondering if there was any easy way I could use a software tool (Such as Blender) to create a 3D map which OpenGL could then load , instead of me having to individually enter every location. Also, is there a easy way to do collision detection in OpenGL. Nothing major, but I want to make sure that the player cannot move through the walls.
If anyone can help me with this, please do. The collision detection is probably more important, but the map would make it so much easier. If there is no way to do the map, is there a way to place a cube in an exact position? I have the positions and items drawn out on a map, but I have only found out about rotations and transformations, not precise locations.

Last edited by anon02; 01-15-2012 at 08:22 AM. Reason: Adding more information.
 
Old 01-15-2012, 12:22 PM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by ThatPerson View Post
I was wondering if there was any easy way I could use a software tool (Such as Blender) to create a 3D map which OpenGL could then load , instead of me having to individually enter every location.
Well you can create some geometry in Blender or so and save (or export) it in a file. Then you'll have to parse the file in your C program (some formats are easier to parse -- *.obj, *.ase,..) to get the data you need. It is not as difficult as it would seem. As far as I know, OpenGL does not provide any functions to load such files, but if you search the internet, perhaps you will be able to find some C libraries for loading the respective formats.

Quote:
Originally Posted by ThatPerson View Post
Also, is there a easy way to do collision detection in OpenGL. Nothing major, but I want to make sure that the player cannot move through the walls.
I have only worked with OpenGL 2.0, so I don't know if that applies for newer version as well, but AFAIK, OpenGL only does graphics. Collision detection (and collision response) is a very complex problem that you'll have to implement yourself. Unless your game is supposed to be *very* realistic (flight simulator, car driving) with a very accurate collision detection, you don't need to use the game geometry you use in openGL for collision detection as well. It will probably suffice to approximate each object with a "box" or "sphere" or a small set off boxes to reduce the complexity. Collision detection for boxes is then a relatively trivial problem.
Again, if you search the internet, you might find some libraries that provide such functionality. I believe there is something called PhysX which should be able to do collision detection, but I have never seen it myself.

Quote:
Originally Posted by ThatPerson View Post
If there is no way to do the map, is there a way to place a cube in an exact position? I have the positions and items drawn out on a map, but I have only found out about rotations and transformations, not precise locations.
You position objects in your scene using modelview transformations (glTranslate*()). It is the same as moving the camera, but in the oposite direction.
 
Old 01-15-2012, 01:08 PM   #3
anon02
Member
 
Registered: Aug 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by millgates View Post
Well you can create some geometry in Blender or so and save (or export) it in a file. Then you'll have to parse the file in your C program (some formats are easier to parse -- *.obj, *.ase,..) to get the data you need. It is not as difficult as it would seem. As far as I know, OpenGL does not provide any functions to load such files, but if you search the internet, perhaps you will be able to find some C libraries for loading the respective formats.



I have only worked with OpenGL 2.0, so I don't know if that applies for newer version as well, but AFAIK, OpenGL only does graphics. Collision detection (and collision response) is a very complex problem that you'll have to implement yourself. Unless your game is supposed to be *very* realistic (flight simulator, car driving) with a very accurate collision detection, you don't need to use the game geometry you use in openGL for collision detection as well. It will probably suffice to approximate each object with a "box" or "sphere" or a small set off boxes to reduce the complexity. Collision detection for boxes is then a relatively trivial problem.
Again, if you search the internet, you might find some libraries that provide such functionality. I believe there is something called PhysX which should be able to do collision detection, but I have never seen it myself.



You position objects in your scene using modelview transformations (glTranslate*()). It is the same as moving the camera, but in the oposite direction.
Perfect. I am going to have a look into PhysX, and for the map I am going to write a API type thing for it so it is easier.
 
Old 01-16-2012, 06:57 AM   #4
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Hey, how did you get started programming OpenGL for Linux? How exactly do you set it up so that you can write OpenGL stuff in your C code? What exactly do you have to download?
 
Old 01-16-2012, 10:04 AM   #5
anon02
Member
 
Registered: Aug 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by resetreset View Post
Hey, how did you get started programming OpenGL for Linux? How exactly do you set it up so that you can write OpenGL stuff in your C code? What exactly do you have to download?
Well, as I had OpenGL already installed, I just added:

Code:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
Then you can use the standard OpenGL things, and when compiling you need to link to GLUT and Gl, so use this line:

Code:
gcc cfile.c -L/usr/lib/libglut.so.3.9.0 -L/usr/lib/libGLU.so.1.3.070701 -lglut -lGLU
So it has the correct headers and the GLU and glut libraries.
 
Old 01-16-2012, 12:58 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Code:
gcc cfile.c -L/usr/lib/libglut.so.3.9.0 -L/usr/lib/libGLU.so.1.3.070701 -lglut -lGLU
-L adds a directory to the library search path, passing a file name doesn't help anything. Since /usr/lib is already searched by default, you don't need -L at all.
 
Old 01-17-2012, 07:29 AM   #7
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Quote:
Originally Posted by ThatPerson View Post
Well, as I had OpenGL already installed


What did you do to install it?
 
Old 01-17-2012, 09:11 AM   #8
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by resetreset View Post
What did you do to install it?
Obviously, nothing if it was already installed.

Are you sure that OpenGL is not already installed on your system?
Btw, you have been asking the same question a lot lately, in several OpenGL related threads. As you have been already told, you should use your favourite search engine to find the answer since the question has been asked and answered many times around the internet. If you have a specific problem, please create a thread and tell us what distro you have, what you have tried so far, what errors you are getting, etc.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ethernet bonding -- link layer detection failover isn't enough, smarter detection? pwn Linux - Networking 1 07-10-2011 10:42 PM
Google maps versus Nokia's OVI maps Aquarius_Girl General 8 05-30-2011 04:26 AM
why won't my collision detection function not work? Quargar Programming 6 11-28-2009 01:34 AM
Tank Game Collision Detection and Bullets SDL/C++ r3dhatter Programming 2 05-30-2004 12:42 PM
bad collision detection in cube_2003_12_23 release LavaDevil94 Linux - Games 0 12-25-2003 12:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration