Advertisement

Is this the best way to do this?

Started by August 20, 2000 03:17 PM
6 comments, last by Mike00 24 years, 3 months ago
I want my ship to move left when I hit the left arrow, right when I hit the right, etc. Here''s what I have: //Global: GLfloat shipx=-1.0, shipy=-3.5, shipz=-10.0; // void Ship(){ glLoadIdentity(); glRotatef(rotatex,1.0f,0.0f,0.0f); glRotatef(rotatey,0.0f,1.0f,0.0f); glRotatef(rotatez,0.0f,0.0f,1.0f); glTranslatef(shipx,shipy,shipz); glBindTexture(GL_TEXTURE_2D, texture[3]); glColor3f(1.0f,1.0f,1.0f); glCallList(shiplist); } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Ship(); } //Then at the bottom: if(keys[VK_LEFT]) shipx-=0.5; if(keys[VK_RIGHT]) shipx+=0.5; if(keys[VK_UP]) shipy+=0.5; if(keys[VK_DOWN]) shipy-=0.5; It goes VERY slow though. I have to hold left for about 8 seconds before the ship moves left, that''s only one space. I keep holding at it moves again. Not very good for a game Any ideas? Thanks! -Mike
i don''t know if this would help, but if you used DriectInput toi handle the input, would that speed things up at all?
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
Advertisement
Although I think there are better ways to do this,at this point this roatation ''method'' shouldn''t cause problems since you only rotate a single object.You should check if you have hardware acceleration and if so,maybe your ship is way too complex.Anyway you could compute a rotation matrix for the whole translation which would propably improve performance but,as I said at this point the performance sould be ok anyway.Hope this helps...

-=Jimmy=-
-=Jimmy=-
Are you using GetAsyncKeyState()?
    #define KEYDOWN(vk_code) (GetAsyncKeyState(vk_code) & 0x8000)if (KEYDOWN(VK_LEFT)){  ...}    


I don''t know if this is what you''re looking for?

I was writing my post but I was preceded by baskuenen

I use

#define KEYDOWN(vkey) (GetKeyState(vkey)&0x8000)

in the same way and it works.

I dont know the difference...try them!
IpSeDiXiT
Hmmm, no I don''t have any #define. What''s the point of it?

I think I have hardware acceleration on but how can I check?

I don''t think my ship is TOO complex.... it has about 8 cylinders, a few half-spheres, a few 3d triangles (forget what they''re called .....

By the way, when I shrink the window (when you go to the corner of it and drag it) so that it''s only about 10% the size of the screen the ship moves really fast...

Thanks!
Advertisement
Hmmmm,my best quess is that you aren''t in HW accel. mode.I don''t know a sure way to test wether you have HW accel(assuming you program in windows not linux) but you can try this...Get one of NEHE''s tutorials e.g. the one with the textured crate you can spin around with the arrow keys.When I tried to run it with no HW accel it was too slow but with HW accel it run fast.So if it renders slow you should try to figure out why you don''t make proper use of your 3D accelerator(assuming you have one).

-=Jimmy=-
-=Jimmy=-
void Ship(){
glLoadIdentity();
glRotatef(rotatex,1.0f,0.0f,0.0f);
glRotatef(rotatey,0.0f,1.0f,0.0f);
glRotatef(rotatez,0.0f,0.0f,1.0f);
glTranslatef(shipx,shipy,shipz);
glBindTexture(GL_TEXTURE_2D, texture[3]);
glColor3f(1.0f,1.0f,1.0f);
glCallList(shiplist);
}



... Shouldn''t he translate first ???
Some says that GL does not make it in the same order, but, what''s that, GL is an immediate mode api . ..huh ???
(you can find me on IRC : #opengl on undernet)

This topic is closed to new replies.

Advertisement