#109390 - shadowghost21 - Fri Nov 17, 2006 11:02 pm
I am writing a First Person Shooter engine (SO I can later port Perfect Dark) and I just started it a few days ago, and I cant get the camera to look left or right then move that direction, as well as keep the 'gun' model I am holding in the camera view. I program in C with the PAlib but I also use the opengl functions that NDSlib provides and I see a lot ofstuff that was written in C++. I belive I need to do something with dot products and trig (damn physics coming back to haunt me). If any one is a 3d coder and would like to help me I would be very thankful. If you could give me a very detailed account of how to work this thing, or even the code(I know I am a mooch but I have been hunched over my computer for way to long and I want to start to port Perfect Dark already I got a lot of textures to add and gameplay mechanics to work on) that would be awesome, you can PM me if you dont want the source you may provide getting loose, And this is NOT for a dev comp, I am doing it for me and the community.
-shadow
#109395 - KoshNi - Fri Nov 17, 2006 11:56 pm
Have you already studied/looked at the devkitPro\examples\nds\input\touch_look example and/or the 10th lesson of the devkitPro\examples\nds\Graphics\3D\nehe 3D tutorial ? It should be helpful since it is actually a fully working fps engine !
Documentation on this topic must exist somewhere : googling for 3d engine fps "how to", I found this http://www.spacesimulator.net/tutorials.html
Keep the faith !
_________________
Sunshine. Beauty. Love. Happiness.
#109425 - shadowghost21 - Sat Nov 18, 2006 6:37 am
I found the space ship examples and have them bookmarked from my research, but it was in C++, but hadn't know where to look in the nds stuff thanks!! But I guess I am going to have to switch to c++ sooner or later.
EDIT: I studied the Source that was provided in the NDSlib examples, but I dont quite understand the loading of "the world" I have 3d objects made into .c files from NDS3d world studio, and I dont quite know how to put them in my project. any ideas?
#109441 - KoshNi - Sat Nov 18, 2006 9:57 am
The file data\World.txt has a similar syntax in Graphics\3D\nehe\lesson10\, Graphics\3D\nehe\lesson10b\ and in input\touch_look\ :
Code: |
NUMPOLLIES 36
// Floor 1
-3.0 0.0 -3.0 0.0 6.0
-3.0 0.0 3.0 0.0 0.0
3.0 0.0 3.0 6.0 0.0
-3.0 0.0 -3.0 0.0 6.0
3.0 0.0 -3.0 6.0 6.0
3.0 0.0 3.0 6.0 0.0
(...)
|
From the way these figures are used in main.cpp, it is possible to know what this stupid matrix -- no offence :) -- means. First, in function SetupWorld, each line of World.txt is read and data is stored in a specific structure :
Code: |
readstr(oneline);
sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v);
sector1.triangle[loop].vertex[vert].x = floattov16(x);
sector1.triangle[loop].vertex[vert].y = floattov16(y);
sector1.triangle[loop].vertex[vert].z = floattov16(z);
sector1.triangle[loop].vertex[vert].u = floattot16(u*128);
sector1.triangle[loop].vertex[vert].v = floattot16(v*128);
|
Now let's have a look at the datatype declarations in the beginning of main.cpp. A sector is composed of a number of triangles which are composed of three vertices :
Code: |
typedef struct tagVERTEX
{
v16 x, y, z;
t16 u, v;
} VERTEX;
typedef struct tagTRIANGLE
{
VERTEX vertex[3];
} TRIANGLE;
typedef struct tagSECTOR
{
int numtriangles;
TRIANGLE* triangle;
} SECTOR;
SECTOR sector1; // Our Model Goes Here:
|
Finally, in function DrawGLScene, each triangle of the sector is rendered during a for loop :
Code: |
x_m = sector1.triangle[loop_m].vertex[0].x;
y_m = sector1.triangle[loop_m].vertex[0].y;
z_m = sector1.triangle[loop_m].vertex[0].z;
u_m = sector1.triangle[loop_m].vertex[0].u;
v_m = sector1.triangle[loop_m].vertex[0].v;
glTexCoord2t16(u_m,v_m); glVertex3v16(x_m,y_m,z_m);
|
Here http://www.mevis.de/opengl/opengl.html (google "glTexCoord") are given the signatures of OpenGl functions (of which only some are implemented in libnds) :
Code: |
void glTexCoord2s(GLshort s, GLshort t)
(...)
PARAMETERS
s, t, r, q
Specify s, t, r, and q texture coordinates. Not all parameters are present in all forms of the command.
|
In short, before you add a vertex you can specify which point of the texture is associated with it.
_________________
Sunshine. Beauty. Love. Happiness.
#109533 - shadowghost21 - Sun Nov 19, 2006 1:42 am
I found a better example of code and finally got it working, only problem... I have a 'gun' model that is supposed to be is sight of the camera at all times, (it is an fps) and when I turn, the gun doesn't move with the camera. and when I rotate the gun will stay in the middle like a 3rd person cam, I want the gun to rotate along with the camera. Any Ideas?
#109563 - KoshNi - Sun Nov 19, 2006 10:00 am
EDIT : The gun must be rotated twice, once to stay in front of the camera (centered on the camera) and once to be in the correct direction (centered on the gun itself).
Why not use a sprite instead ? (this is not advice, this is question)
_________________
Sunshine. Beauty. Love. Happiness.
#109657 - shadowghost21 - Mon Nov 20, 2006 1:42 am
It is for a port of Perfect Dark for the N64 thats why I am using 3d models. But I am having trouble keeping it in front of the camera, I should have paidmore attention during physics (I took the class twice!!) I need to work with dot products, Or so I think, but I dont know what I need to put in for what. I know how to calculate a dot procuct but I dont know what I am doing. It would be a lot easier if I could just zip my project let it loose and have people tell what I need to plug in where, what ever I'll post the part I need help with.
Code: |
//This is my camera and where they look
gluLookAt(objCamera.mPos.x, objCamera.mPos.y, objCamera.mPos.z, objCamera.mView.x, objCamera.mView.y, objCamera.mView.z, objCamera.mUp.x, objCamera.mUp.y, objCamera.mUp.z);
//this is to keep the item in front of the camera, I got this code from a website that was doing camera tutorials and it was from the 3rd person part, so I am basicly treating the gun as a "3rd person",
glTranslatef(objCamera.mView.x,0.0f,objCamera.mView.z);
//now this code works fine I can rotate around the gun but when I move the gun in closer and I move the camera it moves the model around a diferent point of reference.
//this was to get the gun to face out, but the gun would always face the same direction and I belive this is where I need the most help, namly the dot product to produce the y-angle.
glRotatef(0,-90,0);
sniperDrawObject(); |
hope this makes more sense, and I really hope someone can help or point my to a tutorial that does the gun infront of the camera thing.
-shadow
#109666 - DekuTree64 - Mon Nov 20, 2006 2:32 am
Why not just clear the modelview matrix to identity when drawing the gun? It would be possible to invert the camera transformation, but there's no point in doing it.
Once you've cleared the matrix, all you have to do is translate it forward a bit so it's past the near clipping plane, and then down and to the right or whatever to position it where you want on screen. Try setting it up so you can change the translation with the keys, and print out the current position. That way you can tweak it visually rather than just trying numbers and recompliling every time.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#109667 - Rajveer - Mon Nov 20, 2006 2:40 am
Just a question, why dont't you render the level and the gun separately? There's no real reason why you shouldn't (that I can think of) i.e. render the scene then draw the gun ontop of that with:
Code: |
glLoadIdentity();
glPushMatrix();
...Change the current matrix with the camera transformation, draw the scene
glPopMatrix(1);
glPushMatrix();
...Change the view a bit so that the gun appears in the same place, draw the gun
glPopMatrix(1);
|
Test where the gun should be placed (move the camera around till its in the right place) and then when drawing the gun, move/rotate the camera that amount all the time then draw the gun.
EDIT: That's funny, me and DekuTree64 said basically the same thing at the same time :-D
#109680 - shadowghost21 - Mon Nov 20, 2006 5:53 am
This is driving me nuts, I am going to just post the source in a zip, and hopefully some one can help me!!! It needs PAlib also, being as I use PAlib and NDSlib together. They are CPP files although I have no idea how to program in CPP most of the code is C, although the camera.h/cpp are writting by a tutorial I got of the interent and modifyed them to work with the ds. Please help me, this makes no sense I also included the Compiled files just so you can see them.
its a rapidshare.com link as I have an account and its fast, if you dont have an account it dosent matter just download with the free account.
http://rapidshare.com/files/4080120/source.zip
-shadow
#109689 - KoshNi - Mon Nov 20, 2006 10:24 am
I think you'd better put your FPS aside and spend some time playing with OpenGl functions : knowing their behaviour better, it would be painless for you when you start again with your FPS ! You simply are gonna hurt yourself if you are to go too far too fast ... (this is no question, this is advice)
_________________
Sunshine. Beauty. Love. Happiness.
#109693 - Rajveer - Mon Nov 20, 2006 12:07 pm
Agree with KoshNi. Learn how to program and how to program with OpenGL first, it can be confusing when starting out but once you grasp the concept you'll find it's easy.
#109694 - silent_code - Mon Nov 20, 2006 12:47 pm
man, i don't want to be rude, but really, forget about porting anything until you have the skills!
AND @KoshNi: the nehe nds example is very, VERY far away from being a "fully working fps engine"... it ain't an engine at all, it's just a (very simple) demo. calling it an engine is kinda overkill... man. again, i don't intend to be rude. all i want is to remind you about thinking twice about what you post, especially when takling to a beginner.
...
but i'm here to help. ;)
after you initialize the hardware and load your data (i won't talk about that, because it depends on your datasets) you set up the main loop. in that loop you first reset the hw (matrix, gfx, ...) then set up the projection (viewport), draw your gun; rotate to the player's heading, THEN translate to his position and draw the scene; push the matrix for a baddy, then draw him and pop the matrix, repeat for each other non scene object (like them baddies); then draw any tranlutient parts and effects and finally the sky (box or plane or dome). just like that.
(now, not even that would be called an engine. holly poop, it doesn't even have any scene management, not even a real scene graph... again, be careful about your words!)
btw: it's not physics you are looking for, but mathematics. in fact it's linear algebra you're looking for (or whatever it is called in english). feel fre to take a look into a book or two - hell, there are also some great tutorials on the net! :)
ok, that's it. ... though i hope i won't get burned like a witch for this post.
happy coding!
EDIT: ;D
Last edited by silent_code on Mon Nov 20, 2006 2:55 pm; edited 1 time in total
#109698 - KoshNi - Mon Nov 20, 2006 1:58 pm
Quote: |
the nehe nds example is very, VERY far away from being a "fully working fps engine"... it ain't an engine at all, it's just a (very simple) demo. calling it an engine is kinda overkill... |
Yeah I agree. This is only after I read what I had written that I understood the NeHe example wasn't as complete as I mentioned (no collisions with the walls for instance). By the time I knew I was wrong the discussion had gone on so it was useless for me to edit my post.
_________________
Sunshine. Beauty. Love. Happiness.
#109713 - shadowghost21 - Mon Nov 20, 2006 5:18 pm
Did you guys look at the code and compiled program, From what I see only one person ihas downloaded it. I know how to program, I am not an uber programmer, but I learn by doing, and opengl in nintendo ds is psudeo gl anyway. I would like for people to look at my problem insted of just saying know how to program first. I tried every ones suggestions that had posted before I got frustatrated, and I diden't use Nehe's examples they aren't that great, I used these http://www.morrowland.com/apron/tut_gl.php and they work for what I want, I even got the source to quake1, its very hard to find the modual that I want since there is 8 megs of source code to look though. By programming this port I am learning opengl(psudeo on the ds) and when I program large projects I learn alot about programming. I wrote a legocad program, It still has a little work, but I would say that for a first program its pretty damn good!
-shadow
#109721 - KoshNi - Mon Nov 20, 2006 7:09 pm
OK... I downloaded your source this afternoon but as I was at work I didn't try to compile/run it. Now I am at home and this is what I have just done. So I have a better understanding of what the problem is : everything's fine when you move front/back/left/right without changing the direction your aiming at (= the gun is where it's meant to be), but as soon as you click a point of the screen to change where you are looking at, the gun has a weird behaviour and almost disappears from the view (but is still present in the scene, somewhere...??)
EDIT : no this is not it, the gun is still there but no more in view of the camera --> it must be moved to stay in front the camera == somewhere between the position of the camera and the point the camera is looking at
EDIt : I don't understand why the gun can be moved pressing the buttons, it is the camera that should be moved !
_________________
Sunshine. Beauty. Love. Happiness.
#109724 - shadowghost21 - Mon Nov 20, 2006 7:59 pm
I am glad you see the problem I face. It is bizzar indeed. I cant figure it out for the life of me how to keep the gun in view of the camera and make it look like you are holding it. If one takes out the PA_Traslate3D(0,0,5)//to bring the gun to the screen when you rotate the camera it will always be in sight, much like a 3rd person camera, with the gun acting as a person. And I have trouble finding anthing useful in any of the open source 3d shooters I have downloaded.
EDIT: Oh the gun might move when you press a,b,x,y because I put that in for debugging, to see where the gun need to be initally.
EDIT: I changed this glTranslatef(objCamera.mView.x,objCamera.mView.y,objCamera.mView.z);
to this glTranslatef(objCamera.mPos.x, objCamera.mPos.y, objCamera.mPos.z);
this keeps the gun in front of the camera in a fixed position, but when looking from side to side the gun still stays in one spot, at least it is not warping around the scene as it was before. Progess!! I think! Now its just a matter of getting the un to rotate around the y-axis, and pitch up and down, which I dont think would be that hard but it is!!!
-shadow
Last edited by shadowghost21 on Mon Nov 20, 2006 8:55 pm; edited 1 time in total
#109730 - KoshNi - Mon Nov 20, 2006 8:45 pm
Try this :
Code: |
//GET gun to stay infront of the camera!!!!
glTranslatef(objCamera.mPos.x,objCamera.mPos.y,objCamera.mPos.z);
//glTranslatef(objCamera.mView.x,objCamera.mView.y,objCamera.mView.z);
//PA_Translate3D(xpos,ypos,zpos);//using this to get the gun to the screen
|
Not perfect yet, but better than before...
EDIt:cool, this is just what you posted :)
EDIT : I need to sleep. I have added functions to your code so the gun rotates, but not in the correct axis yet... I'll upload the code at PAlib.com for you to get it back.
_________________
Sunshine. Beauty. Love. Happiness.
#109747 - shadowghost21 - Mon Nov 20, 2006 11:24 pm
I finally got it working. I forgot that I didn't want to keep the stylus mouse like controls in. SO I worked the equations from the camera.CPP file and put that in * 5.625 and presto it works, I will reupload so you can see what I did...
http://rapidshare.com/files/4184770/source.zip
now about collisions... just kidding Those *SHOULD* be easy compaired to what I had here! but then again I will be posting in a few days(hours maybe) for the collision stuff
-shadow
#109791 - HyperHacker - Tue Nov 21, 2006 7:34 am
Rajveer wrote: |
Code: |
glLoadIdentity();
glPushMatrix();
...Change the current matrix with the camera transformation, draw the scene
glPopMatrix(1);
glPushMatrix();
...Change the view a bit so that the gun appears in the same place, draw the gun
glPopMatrix(1);
|
|
If I may nitpick... this is an unnecessary use of stack space. There's no need to push the identity matrix. Same effect without this extra push/pop:
Code: |
glLoadIdentity();
...Change the current matrix with the camera transformation, draw the scene
glLoadIdentity();
...Change the view a bit so that the gun appears in the same place, draw the gun
glLoadIdentity(); //you can even remove this if you're not doing anything else afterward |
_________________
I'm a PSP hacker now, but I still <3 DS.
#109793 - silent_code - Tue Nov 21, 2006 7:57 am
draw the gun first. this will discart further fragments from being drawn where the gun is being drawn. just look at my previous post. to achieve the effect of a slightly "lagging" gun (when you rotate the view) first translate the gun, then slightly rotate it into the opposite direction of the head rotation, draw it before doing any player translations and then load the identity matrix.
sorry if you feel that i somehow insulted you, didn't mean to.
#109795 - KoshNi - Tue Nov 21, 2006 8:29 am
Quote: |
http://rapidshare.com/files/4184770/source.zip |
Well done. This is working fine.
_________________
Sunshine. Beauty. Love. Happiness.