PDA

View Full Version : just a kid...



Rapito
03-04-2006, 01:51 PM
hi everyone, since im new here i will tell u about me:

im a 13 years old boy, i live in dominican republic, im n 8th grade, and im a electronics maniac...

i came here asking for some help about Gl and all of it utilities (using ONLY Dev-C++) i want to be a progam and game developer but i need some help making my own shapes :confused: so im askin for some help and for some examples (if u can send them to me or write them)

here is a project i made...
Rapitoproject (http://www.streamload.com/Deliver/Deliver.asp?cxInstID=95178484&nodeID=1435062037&action=2&isDelivery=true&forceSaveAs=true&returnPage=http%3A%2F%2Fwww%2Estreamload%2Ecom%2FN odes%2FInboxDetail%2Easp%3FView%3D1%26drid%3D17323 697)
im looking formward to an answer.
please help this kid to make his dream come true. :rolleyes:

GMan
03-04-2006, 02:36 PM
I would recommend going here first, and using the GLUT tutorials:
http://www.zeuscmd.com/tutorials/opengl/index.php

then once you have done and understand those tutorials I would get the redbook here:
http://www.opengl.org/documentation/red_book_1.0/

Rapito
03-09-2006, 10:54 AM
thx!!!

i would like to know what u think about that project i posted?

RigidBody
03-09-2006, 11:07 AM
i think it would be nice to see something other than

"You cannot access the content "Rapitoproject.zip"."

;)

Rapito
03-09-2006, 11:18 AM
i just realized it myself...
could you tell me a free upload webpage?

Komat
03-09-2006, 11:20 AM
I can not download it. It is telling me that access is denied. Are you sure that you have posted a correct link?

Rapito
03-09-2006, 11:32 AM
im asking you to tell me a web page where i can upload files for free, streamload has some problems,tough...

Komat
03-09-2006, 11:36 AM
Here is list of some free pages: http://www.thefreecountry.com/webhosting/freefilehosting.shtml

Rapito
03-09-2006, 01:00 PM
ok...
at last i could upload da file here :
Rapito\'sProject (http://www.thefilehut.com/userfiles/Rapito/Rapitoproject.zip)

-------------EDIT-----------------
Don't forget to tell me how u like it :p

jide
03-09-2006, 01:23 PM
If you want to be a program and game developer and make your own shapes, you'll have to make your own modeler (or editor). This isn't an easy task, but can go along with the development of your game engine.

You'll have to learn maths (mainly about geometry, trigonometry). That's crucial for making games whether they are 3D or 2D.

Creating shapes, like quads, circles, disks require some knowledge about maths. Study the shapes well.

I quickly looked at your project. The sources look well programmed. This is all I can say for the moment.

What kind of help are you expecting exactly ?

Rapito
03-09-2006, 01:41 PM
im have already a very considerable knowledge about maths (geometry and stuffs) but i cant tell you anythin about trigonometry, if i can have an introduction to trigonometry i would probably learn it very fast (my especiality is math).
...i know a little bit of how makin my own shapes (first i have to create my desired shape with primitives[lInes] then i cjust have to fill them as polygons, right) but i dont understand very much the normal3d function, dont know why it's used for.

and how do i make my own modeler? what is a modeler anyway(if you say that is an editor, what kind of editor)? cant you send (or write) and modeler or shape example?

Dont get mad at me im just a kid wuth a gigantic knowledge thirst (what 13 years old guy u know that have programing knowledge?);p:p

im very gratefull for your help!!!!!

Komat
03-09-2006, 02:01 PM
If you want to be a program and game developer and make your own shapes, you'll have to make your own modeler (or editor).
I do not think that creating modeler on your own is good idea. Many game developers are using third party modeling packages like 3D Studio Max or Maya and invest their time into engine and game instead of making tool which will take long to create and even then it will be for general modeling task inferior to those packages.

Komat
03-09-2006, 02:15 PM
Originally posted by Rapito:
much the normal3d function, dont know why it's used for.

Normals are used for lighting. They represent direction perpendicular to the mesh surface at vertex position.



what is a modeler anyway(if you say that is an editor, what kind of editor)? cant you send (or write) and modeler or shape example?

Modeler is tool that allows you "easily" create 3d meshes for use in your engine. Examples of comercial modelers often used in game development are 3D Studio Max and Maya. For your use it will be better to use Blender http://www.blender.org/cms/Home.2.0.html http://www.blender.org/cms/Home.2.0.html which is freely available with the source code.

Rapito
03-09-2006, 02:17 PM
i oonce tried to use 3d Max studio but it didnt even run it load the loading mini screen and then *buff* it closes, then i stop trying to use it anyway. someone can send me a shape example writed please?

Komat
03-09-2006, 02:29 PM
someone can send me a shape example writed please?
Any complicated shapes are generally not written directly in c++. They are stored in files. They are read from that file and displayed using generic functions independently on what that shape that is.

03-09-2006, 02:46 PM
I do not think that creating modeler on your own is good idea.Sure it is. Well, at least Id, Valve, Croteam, and and Epic think so, to name a few.

For character animation, Maya and its ilk are great, but for game-world editing, not so hot, depending of course on what you're after.

Komat
03-09-2006, 03:47 PM
Originally posted by <simplex>:
Sure it is. Well, at least Id, Valve, Croteam, and and Epic think so, to name a few.
Those named firms are making moneys on licensing theirs engines so any work put into implementing their own modeler that is fully integrated with the engine will paid to them as it is giving them some advantage aginst competition in engine licensing "battle".

If firm does not plan to sell their engine then implementation of really good modeler may be too costly in terms of both price and manpower. If level geometry is significantly complex, Maya or similiar program will have advantage aginst "home made" modeler due to numerous modeling instruments available.

I do not talk here about level editing tool in which externaly created models are combined with gameplay specific elements or various visibility informations to create the final level, such tool is advantageous for any firm.



but for game-world editing, not so hot, depending of course on what you're after.
Yes if you have special requirements or limitations on geometry possible or if you wish to use CSG modeling then certainly specialized tool will be better.

If you construct level by connecting "high polygon soup" parts with some artist defined visibility information using editor then easy of creation of that "polygon soup" in Maya like modeler is advantage.

03-09-2006, 04:03 PM
OK, Komat. Whatever you say. This is a bit OT and so I'll just leave it there.

Rapito, whatever you do, remember to have fun, the rest will follow. Look at the FAQ on this site. It has loads of information on how to get started.

And check this out (lots of links at bottom of page):
http://en.wikipedia.org/wiki/OpenGL

Good luck! :)

Komat
03-09-2006, 05:15 PM
i would like to know what u think about that project i posted? Looks good i have only few mostly subjective comments.

In more complex program it would be better if you write more comments about what functions or nonobvious parts of code are supposed to do. This is especially usefull if code is accessed by more than one people or if you need to modify program code after long time. Try to use more descriptive variable names (angle instead of a and so on). If you define some variable within the function try to do so close to code where it is used and not at the beginning of the function so someone reading that function does not have to move between beginning of the function and code it looks on. During development it is usefull to call glGetError at least once per frame so you can detect some errors you may create (e.g. using incorrect enum as function parameter) There is handy macro assert. It checks if value of its parameter is true (nonzero) and aborts program if it is not. During the abort it prints (in what way this is done is compiler dependent) text of its condition and name of the source file + line number it is used on. It is really usefull if you use it to check that variables are in expected ranges and pointers are not NULL because it allows to catch errors that would otherwise go unnoticed for long time. This macro is defined in such way that it can be compiled out if desired for performance reasons which also means that its should have no side effect (e.g. something like assert( index++ ) should be never used). Unless you really wish to have the first frame cleared with white background, order of glClear and glClearColor in RapitoTriforce should be swapped.

Rapito
03-11-2006, 03:31 PM
Hey guys i havent been online seen afteryesterday....
i just read your messages and the only thing i have to say is "thank you, for helping me so much".

i'been in a lot of discussion boards and every single one of them have told me "go to bed, your just a kid"

im very greatfull to you guys, if all people were like this there will be no worries in the world...
anyway i just finished reading the tutorials of openGL and i learned a lil bit of something, i will keep studing openGL until i master it, who knows maybe you works for me someday at my company "Rapito's" :-p (using OpenGl of course)

i thank you again for everything!!!!!! :)

Rapito
03-11-2006, 03:56 PM
During development it is usefull to call glGetError at least once per frame so you can detect some errors you may create (e.g. using incorrect enum as function parameter) Remember that i only use dev-C++ and it automatically get errors, oh and thac for your critics i have used them all to do a better programing thx :)

Komat
03-11-2006, 04:47 PM
Originally posted by Rapito:

During development it is usefull to call glGetError at least once per frame so you can detect some errors you may create (e.g. using incorrect enum as function parameter) Remember that i only use dev-C++ and it automatically get errorsC++ compiler will report you lexical (e.g. incorectly written float number), syntactical (e.g. missing part of for command) and some semantical (e.g. use of pointer where float should be used) errors you can made in your C++ source code.
It will not detect many errors you can made in use of OGL api because all it can validate is if parameters given to OGL function have correct type.
Problem is that many parameters are integer values so only thing it can check is that you are passing integer to that parameter because otherwise it would have extensive knowledge of OGL api and target HW program will be run on. Examples of situations not detected by c++ compiler:

From compilers point of view glEnable( GL_FLOAT ) is perfectly correct altrough it is nonsense from view of OGL api. You can try to enable feature that is not supported by your card like fifth texture unit on card with four texture units. Some functions can not be called in specific situation. For example many functions can not be called between calls to glBegin and glEnd.

Program with previous errors will pass the c++ compilation without problems. It will however behave incorrectly when run.
Many from previous situations should generate error that can be detected by glGetError function. The exception is if parameter passed to function is logically incorrect while it is valid value. Example of this is call glEnable( GL_LIGHT0 | GL_LIGHT1 | GL_LIGHT2 ) which incorrect however because accidentaly resulting value is valid value of GL_LIGHT3 you will get incorrect behaviour however error will be not detected by glGetError

jide
03-12-2006, 09:05 AM
Originally posted by Rapito:
Hey guys i havent been online seen afteryesterday....
i just read your messages and the only thing i have to say is "thank you, for helping me so much".

i'been in a lot of discussion boards and every single one of them have told me "go to bed, your just a kid"

im very greatfull to you guys, if all people were like this there will be no worries in the world...
anyway i just finished reading the tutorials of openGL and i learned a lil bit of something, i will keep studing openGL until i master it, who knows maybe you works for me someday at my company "Rapito's" :-p (using OpenGl of course)

i thank you again for everything!!!!!! :) This is just because most of people here aren't like the majority ;)

Check what Komat said about glGetError, but don't check it only once per frame, get it as much often as you can, at least during development time. glGetError will report GL error but won't say where it is.

Rapito
03-12-2006, 01:49 PM
lol

thx jide.

hey guys!, right now im reading the red book, yes ANOTHER tutorial, lol, im looking forward to learn hot make Relistic 3d graphics at least to make a 3 seconds game-like animation, but theres something that is driving me crazy: how do i put a timing animation(i mean, make a charcter[polygon, whatever] walk, then after a few seconds do something else)?

Komat
03-12-2006, 03:44 PM
Originally posted by Rapito:
but theres something that is driving me crazy: how do i put a timing animation(i mean, make a charcter[polygon, whatever] walk, then after a few seconds do something else)? OGL itself has no support for animations so it is up to your applications to move and/or modify objects for each frame.
To implement movement you have described your program will remember which animation is currently playing (say some numeric id of the animation), where program is in the animation (e.g. for rotating animation it will be angle by which the object is currently rotated) and for how long from current time that animation should still play. In each frame it will measure time that pass since last frame and will update the progress of the animation (e.g. increase angle of rotation based on time since last frame or, for some animations, move position of object in desired direction). It will also decrease variable indicating for how long the animation should be still playing by time since last frame. If it finds out that animation should not play anymore it will select another animation, new desired duration and progress within the animation and remember that. After all updates are done it will use id of currently selected animation, progress within that animation and other factors (e.g. position of object) to calculate where the object will be and how it will look and will send that to the OGL for rendering.

Rapito
03-14-2006, 03:47 PM
thx komat, i already found out another way to do it, using GLUT_ELAPSED_TIME, but i have to master it yet (can't use it so well tough.

here i'll post another shape i made tell me how u like it please:
RapitoProject2 (http://thefilehut.com/userfiles/Rapito/AviponRojo.zip)

this is a car shape i wrote two ways of it in the exe file, please check it out and tell me how u like it and tell me if i have any mistakes. :D

Komat
03-15-2006, 01:00 PM
Nice looking car :-) It must take you long time to make it. For the next model I would suggest that you implement loading of model from external format that can be generated by Blender or other modeling tool because complexity of manual model creation goes up really quick especially once you add texture coordinates.

Now some new comments to your program.

In function RAPRuedas you call the glOrtho function on modelview matrix. This is technically possible however it is suspicious because this function is mostly used to generate projection matrix. Additionally all parameters are the same so the function will likely generate error (detectable by glGetError) because in that case calculation of several parts of the matrix will cause division by zero (see documentation of glOrtho for the generated matrix). In case of error the glOrtho operation is ignored so matrix should be unchanged.

In function RAPManecillas you call glBegin(GL_QUADS) within glBegin()/glEnd() pair. This is error and glGetError would report that. The errornous operation will be ignored so rendering works however it is not correct.

Call to glFlush before the glutSwapBuffers is not necessary. Equivalent of this is done automatically by the swapbuffers.

In keyboard handling function. The if conditions should contain == (comparison) instead of = (assignment). I assume that the if command here is optimalization attempt because currently the frenos_luz variable can contain only two possible values. In reality if condition, especially based on float values, is from performance point significantly worse than the simple float assignment it avoids. Generaly optimalizations should be only attempted at places where it really matters (as determined by profiling tools) and only if the gain from those optimalizations is significant because the price for many optimalizations is complex to read and complex to modify code. Also not everything that looks like optimalization really optimalization is because it may have nonobvious consequences. For example using really big table of precalculated values may be much slower than calculating those values each time because of price of memory access if accessed part of the table is not in the CPU cache.

Rapito
03-16-2006, 09:46 AM
indeed, it took a while to make da car but it was just an idea i got on school while boring class.
about the texture thing im a lil bit of confused cause i dont know how to texture something i was tring a simple texturing of a block wall paint and i couldn't texture it i dont understand.

i was looking for a way to make my car like a real one, i mean, reflecting light.

thx for telling me the flush and swapbuffer thing(u cant just trust some tutorials, right?)

and in the if thingi i was looking for this:

if i press the key 'f' the red lights pop on
and if i press the key 'f' AGAIN the red lights pop off, but couldnt make it so can u help me a lil bit more :p .

and thx a lot for helping me.

Komat
03-16-2006, 12:17 PM
about the texture thing im a lil bit of confused cause i dont know how to texture something i was tring a simple texturing of a block wall paint and i couldn't texture it i dont understand.

What step do you not understand and how you tried to texture that block?



i was looking for a way to make my car like a real one, i mean, reflecting light.

To give the car the reflective look you have to apply texture with content that looks like it may be reflection of the surrounding (depending on ammount of reflexity the surface should have this may not necessary resemble real surrounding, several smooth color patterns may be sufficient) and apply it in way that depends on a normal of car surface and position of the camera.
Probably the simplest way to do that is create cube texture containing the "reflected" images and use automatic generation of texture coordinates (glTexGen* functions) in GL_REFLECTION_MAP mode.



if i press the key 'f' the red lights pop on
and if i press the key 'f' AGAIN the red lights pop off, but couldnt make it


If you wish to toggle between two states (on/off) it is better to use boolean value like you have done with the F1 key in the specialKeyboard(). In your case you will have for example boolean variable lights_enabled that is toggled in same way the fullscreen variable is. In the RAPCarrito you will then calculate color of the lights using something like

const double frenos_luz = lights_enabled ? 1.0 : 0.5 ;This way there is more obvious that there are two states and the logical act of toggling light is separated from determining what color the light should have on rendered image.

Rapito
03-16-2006, 01:16 PM
to be honest i dont know a thing of texturing i need a step by step texturing class/tutorial.

about the car reflection thing cant be made until i know to texture, but, cant i reflect just iluminaton(lights) besides the environment?

and about the frenos_luz thing i got it working thx ;) :D

Komat
03-16-2006, 01:31 PM
Originally posted by Rapito:
to be honest i dont know a thing of texturing i need a step by step texturing class/tutorial.You can look at one from nehe tutorials http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06



about the car reflection thing cant be made until i know to texture, but, cant i reflect just iluminaton(lights) besides the environment?
You can use OGL lights to lit your model if you provide vertex normals for it. Then if the object has sufficiently small triangles and lights and its material are set correctly, you can see specular highlights on it.

Rapito
03-16-2006, 01:36 PM
ok thx komat im going to try them now.

in the meanwhile i will be putting a simple task to everyone in code advanced: put a project or exe file of any of your owns projects in dev-c++

Rapito
03-16-2006, 03:38 PM
i tried o use ur advice and this is what i get:

#include <GL/openglut.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#define NUMBEROF(x) ((sizeof(x))/(sizeof(x[0])))


static int function_index;
static int slices = 16;
static int stacks = 16;
static double irad = .25;
static double orad = 1.0;
static int depth = 4;
bool fullscreen = false;
bool mouseDown = false;
bool frenos = false;
bool offset = true;
float xrot = 0.0f;
float yrot = 0.0f;
float xdiff = 0.0f;
float ydiff = 0.0f;
double frenos_luz = 0.5;
double luz1 = 0.5;
double luz2 = 0.4;

void RAPCarrito()
{
glBegin(GL_QUADS);

/*BASE*/
/*Base del carro [frente]*/
glColor3d (0.2,0,0); glVertex2f (-0.7,0);
glColor3d (0.4,0,0); glVertex2f (-0.7,0.2);
glColor3d (0.7,0,0); glVertex2f (0.7,0.2);
glColor3d (0.9,0,0); glVertex2f (0.7,0);
/*Base del carro [atras]*/
glColor3d (0.2,0,0); glVertex3f (-0.7,0,-0.5);
glColor3d (0.4,0,0); glVertex3f (-0.7,0.2,-0.5);
glColor3d (0.7,0,0); glVertex3f (0.7,0.2,-0.5);
glColor3d (0.9,0,0); glVertex3f (0.7,0,-0.5);
/*Base del carro [tapa-abajo]*/
glColor3d (0,0,0); glVertex3f (0.7,0,-0.5);
glColor3d (0.2,0.2,0.2); glVertex3f (-0.7,0,-0.5);
glColor3d (0.15,0.15,0.15); glVertex3f (-0.7,0,-0.0);
glColor3d (0.2,0.2,0.2); glVertex3f (0.7,0,-0.0);
/*Base del carro [tapa-arriba]*/
glColor3d (0.9,0,0); glVertex3f (0.7,0.2,-0.5);
glColor3d (0.4,0,0); glVertex3f (-0.7,0.2,-0.5);
glColor3d (0.4,0,0); glVertex3f (-0.7,0.2,-0.0);
glColor3d (0.9,0,0); glVertex3f (0.7,0.2,-0.0);
/*Base del carro [tapa-lado-izquierdo]*/
glColor3d (0.2,0,0); glVertex3f (-0.7,0,-0.5);
glColor3d (0.4,0,0); glVertex3f (-0.7,0.2,-0.5);
glColor3d (0.7,0,0); glVertex3f (-0.7,0.2,0);
glColor3d (0.0,0,0); glVertex3f (-0.7,0,0);
/*Base del carro [tapa-lado-derecho]*/
glColor3d (0.4,0,0); glVertex3f (0.7,0,-0.5);
glColor3d (0.7,0,0); glVertex3f (0.7,0.2,-0.5);
glColor3d (0.7,0,0); glVertex3f (0.7,0.2,0);
glColor3d (0.4,0,0); glVertex3f (0.7,0,0);

/*CAPOTA*/
/*Capota del carro [base-frente]*/
glColor3d (0.4,0,0); glVertex3f (-0.5,0.2,0);
glColor3d (0.3,0,0); glVertex3f (-0.3,0.45,0);
glColor3d (0.7,0,0); glVertex3f (0.3,0.45,0);
glColor3d (0.8,0,0); glVertex3f (0.5,0.2,0);
/*Capota del carro [base-atras]*/
glColor3d (0.4,0,0); glVertex3f (-0.5,0.2,-0.5);
glColor3d (0.3,0,0); glVertex3f (-0.3,0.45,-0.5);
glColor3d (0.7,0,0); glVertex3f (0.3,0.45,-0.5);
glColor3d (0.8,0,0); glVertex3f (0.5,0.2,-0.5);
/*Capota del carro [tapa-arriba]*/
glColor3d (0.4,0,0); glVertex3f (-0.3,0.45,0);
glColor3d (0.3,0,0); glVertex3f (-0.3,0.45,-0.5);
glColor3d (0.7,0,0); glVertex3f (0.3,0.45,-0.5);
glColor3d (0.8,0,0); glVertex3f (0.3,0.45,0);
/*Capota del carro [tapa-lados-izquierda]*/
glColor3d (0.5,0,0); glVertex3f (-0.5,0.2,0);
glColor3d (0.5,0,0); glVertex3f (-0.5,0.2,-0.5);
glColor3d (0.3,0,0); glVertex3f (-0.3,0.45,-0.5);
glColor3d (0.3,0,0); glVertex3f (-0.3,0.45,0);
/*Capota del carro [tapa-lados-derecha]*/
glColor3d (0.7,0,0); glVertex3f (0.5,0.2,0);
glColor3d (0.7,0,0); glVertex3f (0.5,0.2,-0.5);
glColor3d (0.8,0,0); glVertex3f (0.3,0.45,-0.5);
glColor3d (0.8,0,0); glVertex3f (0.3,0.45,0);

/*LUCES DE FRENTE*/
/*LADO DERECHO*/
/*luces de frente [lado-derecho-ATRAS]*/
glColor3d (0.5,0.4,0); glVertex3f (0.73,0.15,-0.1);
glColor3d (0.8,0.8,0); glVertex3f (0.73,0.15,-0.2);
glColor3d (0.8,0.8,0); glVertex3f (0.73,0.05,-0.2);
glColor3d (0.8,0.8,0); glVertex3f (0.73,0.05,-0.1);
/*luces de frente [lado-derecho-FRENTE]*/
glColor3d (0.5,0.4,0); glVertex3f (0.725,0.15,-0.1);
glColor3d (0.5,0.4,0); glVertex3f (0.725,0.15,-0.2);
glColor3d (0.5,0.4,0); glVertex3f (0.725,0.05,-0.2);
glColor3d (1.0,1.0,0); glVertex3f (0.725,0.05,-0.1);
/*luces de frente [lado-derecho-tapa-derecho]*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.1);
/*luces de frente [lado-derecho-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.2);
/*luces de frente [lado-derecho-tapa-arriba*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.2);
/*luces de frente [lado-derecho-tapa-abajo*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.2);

/*LADO IZQUIERDO*/
/*luces de frente [lado-derecho-ATRAS]*/
glColor3d (0.5,0.4,0); glVertex3f (0.73,0.15,-0.3);
glColor3d (0.8,0.8,0); glVertex3f (0.73,0.15,-0.4);
glColor3d (0.8,0.8,0); glVertex3f (0.73,0.05,-0.4);
glColor3d (0.5,0.4,0); glVertex3f (0.73,0.05,-0.3);
/*luces de frente [lado-derecho-FRENTE]*/
glColor3d (0.5,0.4,0); glVertex3f (0.725,0.15,-0.3);
glColor3d (0.5,0.4,0); glVertex3f (0.725,0.15,-0.4);
glColor3d (0.5,0.4,0); glVertex3f (0.725,0.05,-0.4);
glColor3d (1.0,1.0,0); glVertex3f (0.725,0.05,-0.3);
/*luces de frente [lado-derecho-tapa-derecho]*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.3);
/*luces de frente [lado-derecho-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.4);
/*luces de frente [lado-derecho-tapa-arriba*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.15,-0.4);
/*luces de frente [lado-derecho-tapa-abajo*/
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (0.725,0.05,-0.4);

/*LUCES DE ATRAS*/
/*LADO IZQUIERDO*/
/*luces de atras [lado-izquierdo-ATRAS]*/
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.15,-0.3);
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.15,-0.4);
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.05,-0.4);
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.05,-0.3);
/*luces de atras [lado-izquierdo-FRENTE]*/
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.15,-0.3);
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.15,-0.4);
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.05,-0.4);
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.05,-0.3);
/*luces de atras [lado-izquierdo-tapa-derecho]*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.3);
/*luces de atras [lado-izquierdo-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.4);
/*luces de atras [lado-izquierdo-tapa-arriba*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.4);
/*luces de atras [lado-izquierdo-tapa-abajo*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.4);

/*LADO DERECHO*/
/*luces de atras [lado-derecho-ATRAS]*/
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.15,-0.2);
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.15,-0.2);
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.05,-0.2);
glColor3d (frenos_luz,0,0); glVertex3f (-0.73,0.05,-0.1);
/*luces de atras [lado-derecho-FRENTE]*/
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.15,-0.2);
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.15,-0.1);
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.05,-0.1);
glColor3d (frenos_luz,0,0); glVertex3f (-0.725,0.05,-0.2);
/*luces de atras [lado-derecho-tapa-derecho]*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.1);
/*luces de atras [lado-derecho-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.2);
/*luces de atras [lado-derecho-tapa-arriba*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.15,-0.2);
/*luces de atras [lado-derecho-tapa-abajo*/
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20); glVertex3f (-0.725,0.05,-0.2);

glEnd();
}

void RAPRuedas()
{
/*RUEDAS*/
/*1ra RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (-0.3,0,0);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,0.03);
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

/*2da RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (0.4,0,0);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,0.03);
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

/*3ra RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (0.4,0,-0.5);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,-0.03);
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

/*4ta RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (-0.3,0,-0.5);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,-0.03);
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();
}
void RAPMufler()
{
/*Mufler*/
/*Inicio de mufler[hacia abajo]*/
glBegin(GL_QUADS);
glColor3f (0.52,0.52,0.52); glVertex3f(-0.2,0,-0.1);
glColor3f (0.52,0.52,0.52); glVertex3f(-0.2,0,-0.2);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.2,-0.06,-0.2);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.2,-0.06,-0.1);
/*Mufler[trompa]*/
glColor3f (0.42,0.42,0.42); glVertex3f(-0.2,-0.06,-0.2);
glColor3f (0.42,0.42,0.42); glVertex3f(-0.75,-0.06,-0.2);
glColor3f (0.30,0.30,0.30); glVertex3f(-0.75,-0.06,-0.1);
glColor3f (0.30,0.30,0.30); glVertex3f(-0.2,-0.06,-0.1);
/*Mufler[trompa-lado-derecho]*/
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.00,-0.2);
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.06,-0.2);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.06,-0.2);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.00,-0.2);
/*Mufler[trompa-lado-izquierdo]*/
glColor3f (0.25,0.25,0.25); glVertex3f(-0.2,-0.00,-0.1);
glColor3f (0.25,0.25,0.25); glVertex3f(-0.2,-0.06,-0.1);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.06,-0.1);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.00,-0.1);
/*Mufler[final de la trompa-arriba]*/
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.0,-0.2);
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.0,-0.1);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.75,-0.0,-0.1);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.75,-0.0,-0.2);

glEnd();
}
void RAPVentanas ()
{
/*VENTANAS*/
/*1ra Ventana*/
glBegin (GL_QUADS);
glColor3d (0,0,0);
glVertex3f (0.4,0.2,0.001);
glVertex3f (-0.0,0.2,0.001);
glVertex3f (-0.0,0.4,0.001);
glVertex3f (0.25,0.4,0.001);
/*2da Ventana*/
glVertex3f (-0.4,0.2,0.001);
glVertex3f (-0.05,0.2,0.001);
glVertex3f (-0.05,0.4,0.001);
glVertex3f (-0.25,0.4,0.001);
/*3ra Ventana*/
glVertex3f (0.4,0.2,-0.51);
glVertex3f (-0.0,0.2,-0.51);
glVertex3f (-0.0,0.4,-0.51);
glVertex3f (0.25,0.4,-0.51);
/*4ta Ventana*/
glVertex3f (-0.4,0.2,-0.51);
glVertex3f (-0.05,0.2,-0.51);
glVertex3f (-0.05,0.4,-0.51);
glVertex3f (-0.25,0.4,-0.51);
/*5ta Ventana*/
glVertex3f (0.35,0.4,-0.45);
glVertex3f (0.35,0.4,-0.051);
glVertex3f (0.5,0.22,-0.051);
glVertex3f (0.5,0.22,-0.45);
/*6ta Ventana*/
glVertex3f (-0.35,0.4,-0.45);
glVertex3f (-0.35,0.4,-0.051);
glVertex3f (-0.475,0.25,-0.051);
glVertex3f (-0.475,0.25,-0.45);

glEnd();
}

void RAPManecillas()
{
/*MANECILLAS*/
/*Manecilla de Acompaņante*/
glBegin(GL_QUADS);
glVertex3f (0,0.1,0.001);
glVertex3f (0.15,0.1,0.001);
glVertex3f (0.15,0.15,0.001);
glVertex3f (0,0.15,0.001);
/*Manecilla de Acompaņante [parte-abrir]*/
glColor3f (0.25,0.25,0.25); glVertex3f (0,0.115,0.025);
glColor3f (0.25,0.25,0.25); glVertex3f (0.15,0.115,0.025);
glColor3f (0.50,0.50,0.50); glVertex3f (0.15,0.15,0.001);
glColor3f (0.50,0.50,0.50); glVertex3f (0,0.15,0.001);
/*Manecilla de Acompaņante*/
glBegin(GL_QUADS);
glColor3d (0,0,0);
glVertex3f (0,0.1,-0.501);
glVertex3f (0.15,0.1,-0.501);
glVertex3f (0.15,0.15,-0.501);
glVertex3f (0,0.15,-0.501);
/*Manecilla de Acompaņante [parte-abrir]*/
glColor3f (0.25,0.25,0.25); glVertex3f (0,0.115,-0.525);
glColor3f (0.25,0.25,0.25); glVertex3f (0.15,0.115,-0.525);
glColor3f (0.50,0.50,0.50); glVertex3f (0.15,0.15,-0.501);
glColor3f (0.50,0.50,0.50); glVertex3f (0,0.15,-0.501);

glEnd();
}
static void shapesPrintf (int row, int col, const char *fmt, ...)
{
static char buf[256];
int viewport[4];
void *font = GLUT_BITMAP_9_BY_15;
va_list args;

va_start(args, fmt);
(void) vsprintf (buf, fmt, args);
va_end(args);

glGetIntegerv(GL_VIEWPORT,viewport);

glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho(0,viewport[2],0,viewport[3],-1,1);

glRasterPos2i(
glutBitmapWidth(font, ' ') * col,
- glutBitmapHeight(font) * (row+2) + viewport[3]
);
glutBitmapString (font, (unsigned char *) buf);

glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}

/* GLUT callback Handlers */

bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);

return true;
}


void display()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);

glRotatef(xrot,0.5f,0.0f,0.0f);
glRotatef(yrot,0.0f,0.5f,0.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (offset)
{
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
}

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glPushMatrix();
glTranslated(0,0,0.5);
RAPCarrito();
RAPMufler();
RAPVentanas ();
RAPManecillas();
RAPRuedas();
glPopMatrix();
glDisable(GL_LIGHTING);
shapesPrintf (1, 3, "Se prende las luces de freno al f y se apagan a shift+f.");
shapesPrintf (2, 3, "Este programalo hice yo rapito...");
shapesPrintf (3, 3, "...Si, yo Robert", slices, stacks);
if (offset)
glDisable(GL_POLYGON_OFFSET_FILL);


glFlush();
glutSwapBuffers();
}

void resize(int w, int h)
{
const float ar = (float) w / (float) h;

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if( ar > .5 )
glFrustum( -ar, ar, -1.0, 1.0, 2.0, 100.0 );
else
glFrustum( -1.0, 1.0, -1/ar, 1/ar, 2.0, 100.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}

void idle()
{
if (!mouseDown)
{

yrot += 1.0f;
}

glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27 :
exit (0); break;

case 'f' :
if (frenos_luz = 0.5) frenos_luz = 1.0; break;
case 'F' :
if (frenos_luz = 1.0) frenos_luz = 0.5; break;


}
}

void specialKeyboard(int key, int x, int y)
{

if (key == GLUT_KEY_F1)
{
fullscreen = !fullscreen;

if (fullscreen)
glutFullScreen();
else
{
glutReshapeWindow(500, 500);
glutPositionWindow(50, 50);
}
}
}


void mouseMotion(int x, int y)
{
if (mouseDown)
{
yrot = x - xdiff;
xrot = y + ydiff;

glutPostRedisplay();
}
}

void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseDown = true;

xdiff = x - yrot;
ydiff = -y + xrot;
}
else
mouseDown = false;
}


const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 5.0f, -5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

int
main(int argc, char *argv[])
{
glutInitWindowSize(640,480);
glutInitWindowPosition(40,40);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("OpenGLUT Shapes");

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutSpecialFunc(specialKeyboard);
glutIdleFunc(idle);

glClearColor(1,1,1,1);

glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);



glutMainLoop();

return EXIT_SUCCESS;
}

Komat
03-16-2006, 05:06 PM
Originally posted by Rapito:
i tried o use ur advice and this is what i get
Please, do not include such long source code directly in the post.

There are two problems. First your car has very low polygon count so specular highlights will not work well on it (try to increase number of parts from which wheels are constructed by using 50 instead of 15 in glutSolidTorus call to see the difference on the wheels).

Second you are not specifying vertex normal using glNormal3* call so last value from rendering of wheels will be used for rest of the mesh so lighting will not work correctly on the rest of the mesh.

Rapito
03-18-2006, 07:44 AM
but i dont know what is the normal3* for...

Komat
03-18-2006, 12:34 PM
Originally posted by Rapito:
but i dont know what is the normal3* for... By that group of functions you specify vertex normal which is direction perpendicular to object surface in that vertex. The lighting uses it to determine amount of lighting applied to the surface at vertex.
Basically if normal points directly towards the light, diffuse lighting will be at its maximal power while if normal is pointing from the light there will be no diffuse lighting at all. Power of specular lighting depends on direction of normal and position of camera. Exactly how ammount of lighting is calculated is written in Opengl specification (http://www.opengl.org/documentation/specs/version2.0/glspec20.pdf) in chapter 2.14.1

Rapito
03-19-2006, 06:23 AM
ok...
and for example how do i make the source of lighting be the /*LUCES*/?

Komat
03-20-2006, 05:48 PM
and for example how do i make the source of lighting be the /*LUCES*/? I do not uderstand your question.

k_szczech
03-21-2006, 05:50 AM
You will probably not like the idea, but I think it's the right way to start: create a 2-d shooter or platform game.
This way you need only:
-rendering simple quads in 2d
-use texturing
-use blending (for some speciall effects)
-depth test (optional)
And you don't need:
-fog
-lighting
-normal vectors
-complex collision detection and physics
-no 3d models at all!
-only 2d vectors, and these are simple
-no matrix knowledge
-no dot product and cross product knowledge
-no trigonometry

So, making some kind of 2d shooter is a best way of mastering mechanisms like texturing and blending in very short time.

When making a 3d-game you need to strongly understand (and not just know how to compute) dot products, cross products, and most likely multiplying vector by matrix. And this is just the beginning.

When I started programming I was 12 years old, and I was very good at maths, too. However - my thinking was bad. I used to create models by writting instructions that draw them - just like you did. This may work at the beginning - but how would you detect collision between two such cars? You really need to start storing all vertex coordinates in an array.

I strongly recommend you to try 2d game first. Although it sounds less exciting it's more reasonable. And still you can put some 3d elements in there. for example - platform game can have platforms made of 3-d boxes covered with brick texture. Or 2-d shhoter can have some boxes, barrels, walls etc. Only the characters would have to be 2d.
This way you do not need any modeller, and can make a game way faster.

Think of it.

MZIskandar
03-21-2006, 06:34 PM
Hi all..

This topic is very cute yet very very educational..

2D games is not as exciting as 3D games - it is plain and boring. But what k_szczech said is right, and i have to agree! Spend more time on the logic and the usage of OpenGL API. 3D model can be done with modeller such as GMax(Free 3D modeller www.autodesk.com/gmax). (http://www.autodesk.com/gmax).)

Rapito
03-25-2006, 09:38 PM
thx k_szczech hey i got u a question about what u said:

how do i recognize the collision with two objects and a response for this phenomenon?

Rapito
03-25-2006, 09:41 PM
komat forget the question i made i already made it...

i have another question, tough
how can i make a polygon or line make a curve?

Komat
03-26-2006, 07:15 AM
how do i recognize the collision with two objects and a response for this phenomenon? To test the collision you need to have information about space occupied of both objects (collision geometry). The detailness of collision geometry depends on your objects (both geometry and movement parameters) and what you need to do with the result.
For example if you need to explode rocket on the collision, you can have very simple representation of geometry (e.g. bounding box) while if you do billiard game the collisions should be calculated as exactly as possible. Sometimes you have to find ballance between precision and performance by using simpler collision geometry (e.g. bounding box) that is calculated much faster than the more precise one (e.g. polygonal mesh).
You may have several levels of collision geometry for single object and you test them in the order of increasing test complexity until you find one that says there is no collision or until you find collision in all of them. This way you skip the time consuming tests when one from simpler tests says that objects do not have chance for collision. Example of such order is bounding sphere, bounding box, polygonal geometry. As before, you need to compare the comulated cost of all the tests with cost of doing the last test only. For example if your objects are almost always in collision the precise test will be almost never skipped and you pay additional time for those simpler collision tests.

Some examples of informations about geometry:
Bounding sphere/circle. Sphere with such size that the entire object geometry is within it. Sphere center position offten influences its size so it may be desired to offset the sphere from center of the object which somewhat increases the collision calculation complexity so it depends on gains you get from that. For example if you do simple "Asteroids" like shooter where both ship and asteroids have circle like geometry around object position the offset is not necessary and bounding circles are perfectly fine. Bounding sphere is not precise for long tall objects because they need to have big sphere so there is huge difference between both geometries so if you are creating space sim with loong ships, using only spheres is not good idea. Test of collision between two spheres is done by comparing distance between them with sum of theirs radius. Bounding cylinder. Usable as first level of test for collisions between projectiles and human like characters. For some weapons it may entirely suffice (e.g. rocket) for some (e.g. pistol bullet) you may need additional test on geometries for individual body parts if cylinder for entire character says there is hit. Otherwise you may get hits from bullets passing say quarter of meter before the character and blood floowing from the air. Bounding box. Box around the geometry. There are two types of bounding boxes. First are axis aligned bounding boxes (AABB). Those boxes have theirs sides paralel to some space (often the world space) so test between both AABB is done by comparing ranges between minimal and maximal value on individual axes. If ranges of two boxes intersect in all three axes there is collision. Problem with AABB is that they may be bad fit to the original geometry (e.g. oblique long rod) and they may change with object rotations. The second type are oriented bounding boxes OBB. They are boxes that are rotated and translated so they fit the geometry as close as possible. They are also rotated when geometry rotates. They do not have the mentioned problems of AABB howevever collision testing is not so simple anymore. Meshes in various preprocessed form (e.g. BSP trees, OBB trees,..). For more information about this see
OPCODE (http://www.codercorner.com/Opcode.htm) , SOLID (http://www.win.tue.nl/~gino/solid/index.html) and RAPID (http://www.cs.unc.edu/~geom/OBB/OBBT.html)

If your game objects move by small speeds relative to time between tests you can test the end positions only. To test for collision between two objects in this case you do test between their collision geometries for positions from current frame.
If the speed is high (e.g. projectile) or high precision is required (e.g. billiard) you may need to test geometry surrounding the object trajectory because otherwise you may mis a collision. This is much more complicated in general case however if the only high speed things are the small projectiles, you may test the intersection of object geometry at position from current frame with line representing movement of the projectile since the last frame. While this test for projectile may still mis a collision, it will do mostly in situations where that is likely anyway and it is no problem in most such cases.

If you have high number of objects in the scene it may be not feasible to test all pairs. In that case you have to split the scene in parts and test collision between objects that are impinging a same part. For overview of some partioning methods see this lecture (http://cgg.ms.mff.cuni.cz/~pepca/lectures/pdf/datasurvey.pdf) . That lecture is in czech however images should be clear.

Once you have determined that objects are in collision you will determine what to do. This greatly depends on your specific game and objects in question (e.g. rocket explodes, billiard balls bounces, player slides along the wall). For some handling you need only the fact that the collision happened (e.g. for rocket hit). For other things you may need to know the place where it happened (e.g. for player hit by bullet) or even how depth is the intersection of those objects (e.g. for "real" physics). Depending on collision geometries and collision testing method some of those informations may be already present. The other additional informations need to be calculated when collision is detected. For first attempts I suggest that you avoid the "real" physics and use simple aproximations. If you wish to get more informations about physics you can look at ODE (http://www.ode.org/) which is open source physical library.

Komat
03-26-2006, 07:35 AM
i have another question, tough
how can i make a polygon or line make a curve? If you are talking about giving the polygon the look of curved surface, you can use the vertex normals or the per-pixel normals (aka normal maps) together with lighting to give it part of appearance of curved surface. However that is only a optical ilusion which will break if you see polygon from the side or if polygon intersects with other polygon.
You can not get true curve effect without dividing polygon into more polygons that will be positioned along the curve surface. You have to divide the curved surface into such small triangles that it looks good. The extreme is if you divide surface in such way that each triangle has size of pixel. This will get you really curved looking surface likely killing your performance in the process (this is actually done by some offline renderers from 3d modeling packages). The same thing with the division is true for lines.

In GLU library there are helper function that can help you with the subdivision of surface or polygon however I have never used them.

Komat
03-26-2006, 08:07 AM
There is Nehe tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30) talking about collisions. I have not read it however it may be helpfull to you.

Rapito
03-26-2006, 10:44 AM
u know komat is very hard to me to understand NeHe's tutorials they r just 2 complex, remember dat time i needed a texure mapping tutorial, i didn't understood NeHe's i had to read another one more simple, but thc anyway :p ;)

MZIskandar
03-26-2006, 11:46 AM
After learning and understanding the basic concept of physic in programming, you might want to explore the tokomak physic engine. You can integrate it using devcpp and opengl. Try it. Its fun!

Rapito
03-26-2006, 01:34 PM
i dont understand what u try to say
what is the tokomak physyk?

Komat
03-26-2006, 02:42 PM
The correct name is Tokamak http://www.tokamakphysics.com/ It is physics library designed for games. It calculates collisions and physics based movement.

Ehsan Kamrani
03-26-2006, 05:20 PM
I guess that Novodex is a better API to do physics. My friend in my corporation uses from this API to make the physics of our game. But as we are in our new year-The new year of iranian people- I don't know where he is ;) Unfortunately i have not enough knowledge about Novodex. But as i know, new physics cards support this API. My friend has said to me that all the examples of the Novodex SDK use from OpenGL to create the objects. So after learning OpenGL, you can simply learn Novodex.
-Ehsan-