Advertisement

Timing - again

Started by February 27, 2000 02:38 PM
13 comments, last by kieren_j 24 years, 6 months ago
Lutrosis,

Thanks for pointing your timing article to me You are doing basically the same thing that I've been doing and the results are the same. In your case you take velocity of 40/frequency i.e. 1000 then multiplying by amount of milliseconds elapsed since last frame i.e. 100. So (40/1000ms)*100ms = 4 pixels per frame.

I obtain seconds it took to render the last frame i.e. (100ms/1) * (1s/1000ms) = 0.1 seconds. I then multiply the velocity of 40m/s or pixels by 0.1 seconds and get the same value of 4 pixels per frame. In your case you can take 100ms divide by 1000ms first, yielding 0.1s, then multiply by 40 just like I did.

We are both trying to move less per frame on fast cpus and more per frame on slow cpus thus covering the same distance PER UNIT TIME or per one second. So let's say we want to move 500 pixels per second on both the fast and slow cpu. We simply move in smaller steps on the fast cpu because it can spit out many more frames than that of the slow cpu. Be carefull about the time in ticks return value since on very fast cpus it could become zero, meaning the frame was rendered in less than one millisecond.

Anyway, nice work with your timing article and it's actually good to have people discussing this issue and show off their code so I and many others can learn from it. Thanks for doing that

Jerry

P.S. If I made interpretation mistakes of your code please don't hesitate to stop here again and let me know.

Edited by - JD on 3/3/00 4:29:04 AM
JD

I understand your point, but if the next position is after the object (I am moving at 10 pixels at time and the object is 5 pixels). It will be a valid new position. Thats my problem.

I have read some stuff about it, tracing a vector from old and new positions, but don''t know how to do the collision tests on that way. And there is another problem, ''cos I need to know where is the collision, that''s a ball (like arkanoid stuff)
http://www.stas.net/rafael/icq: 11915640
Advertisement
For 2D collisions I think that you simply check the x and y coordinates of let''s say a missile against your moving object''s coordinates. Let''s say that your object has an x-coordinate of 50, and y-coordinate of 100 or (50, 100). The moving missile''s coordinates are (60, 100) thus it has the same height as that of your object and is 10 pixels to the right of it.

That was the position of objects in the last frame. Before the next frame gets drawn the program calculates new position for the missile. Let''s say that new position is (40, 100) or 10 pixels on the left of your object thus it went through. You simply do a comparison of the missile x-coord with your object''s x-coord.

if(missile.x <= my_ship.x)

then the collision happened but only if they are at the same height. Maybe I''m confused as you are but this is how I am going to do my collisions and I think it will work. Maybe someone more experienced with collisions can help you or try searching through this forum and the web for better answers. Good luck.

Jerry
Collision detection can be a problem sometimes, especially when you have to move an object lots of pixels in one frame. I''m in the process of perfecting some collision detection methods that would work for you, but it''s complicated. It involves treating the vectors of the two moving objects as line segments, getting their equations, and solving them for an intersection. Depending on where the intersection is, you can tell if they would have collided. I know, it probably sounds confusing, but I''d love to help you out. If you''re interested put up another post and/or send me an e-mail at lutrosis34@hotmail.com. I can send you a demo and explain things thouroughly. Heck, send me your code and I''ll have a look.

-Lutrosis
-Lutrosis#define WHOOPS 0class DogClass {public: CDog() { printf("Ruff!"); } Run() { printf("Run!"); } Crash() { printf("%d",100/WOOPS); }};DogClass CDog;CDog.Run();CDog.Crash();
Erm...maybe nobody read my question? I asked how to use the multimedia timers!
timeGetTime() has a bug which means it only does around 5ms on most systems, and not many systems have HighPerformanceCounter functions! I''m talking about the windows multimedia timers!

This topic is closed to new replies.

Advertisement