Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


objects moving too fast and discontinuous

This topic is 5935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Dear All, The simple program about a small blue object(earth) encircle a center yellow object(sun) fails. The earth move so fast even though the theta increment is very small. Not only that it has discontinuous motion. When I block out the memset(vscreen), to display all the previous traces of images, the screen output shows only 4 or 5 traces of circles for small multiple of 2(phi) and still discrete no. of circle for large multiple of 2(phi) in the limiting condition to reset theta=0, at the end of while loop. I would expect the increment of theta to be stepwise, each small increment followed by plot to vscreen and plot to real screen so there shouldn''t be any discontinous and wild running images being plot to the real screen. The related segments are as follows: typedef struct { long rad_orb; float theta_start_deg; long rad_planet; dword color; } planet; void planet_move(planet planet_t) { int x1,y1,xcen,ycen; x1=planet_t.rad_orb*cos(theta_rad); y1=planet_t.rad_orb*sin(theta_rad); solid_circle2(sun_xcen+x1,sun_ycen+y1, planet_t.rad_planet,earth_color_w); } void wait_for_retrace() { while (inportb(0X03DA) & 0x08); while (!(inportb(0x03DA) & 0x08)); } planet earth = {100,0,20,0x0000ff}; int main() { (here is get video info) vscreen=((word *)malloc(2*800*601)); if (vscreen==0) { printf("cannot allocate memory"); exit(-1); } memset(vscreen,0,2*800*602); float r1,g1,b1; _24toRGB(earth.color, &r1, &g1, &b1); earth_color_w=RGBto16(r1,g1,b1);//earth_color_w(global) sun_xcen=400; sun_ycen=300; int sun_rad=30; dword sun_color=0xffff00; _24toRGB(sun_color, &r1, &g1, &b1); dword sun_color_w=RGBto16(r1,g1,b1); set_mode_normal(mode);//mode defined earlier 0x114; theta_rad= ((earth.theta_start_deg)/180)*3.14; while (!kbhit()) { solid_circle2(sun_xcen, sun_ycen,sun_rad, sun_color_w); planet_move(earth); wait_for_retrace(); copy_to_vesa_screen_16bit(vscreen,800*600);//contains bank switching steps. memset(vscreen,0,2*800*602); if (theta_rad<=10000000*6.28) theta_rad+=theta_rad+ 0.0001; else theta_rad=0; memset(vscreen,0,2*800*602); //delay(200); } Hope you can give a way to make the earth orbiting more continuous and slower. Thank you Patrick

Share this post

Link to post
Share on other sites
HUGE error in your code though. you are allocating, memseting and dealing with the video buffers incorrectly in the code. your height should be 600 not 601 or 602, just 600.

theta_rad+=theta_rad+ 0.0001;

is like saying
theta_rad = theta_rad*2+0.0001;

you have to decide, you want the += notation or the a=a+ notation.

though everything else seems good. DEFINATLY fix the memory issues you have, they are causing problems (or will cause problems) later on.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!