Advertisement

how would I .....

Started by May 03, 2001 03:39 PM
10 comments, last by SCRUB 23 years, 6 months ago
Go back X amount from the origin and then spin around it, while constantly looking at the origin ?
LE SCRUB
xpos -= cos[heading]*distance;
zpos += sin[heading]*distance;

beware I use lookups for sin/cos

"Like all good things, it starts with a monkey.."

Edited by - monkeyman on May 3, 2001 4:45:53 PM
"Like all good things, it starts with a monkey.."
Advertisement
That just get you moving around in a circle right ?
while constantly looking at the origin is the bit im a bit confusted by.

Interesting little doosey
LE SCRUB
well, you have to increment the heading to spin around, but that code will set your position away from the origin at the correct angle according to your heading..

beware if you use lookups for sin/cos(not really too necessary these days, it''s an old dos habit of mine you need to check for when it goes over 359 degrees ans reset to 0, otherwise CRASH

"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
quote:
beware if you use lookups for sin/cos(not really too necessary these days, it''s an old dos habit of mine you need to check for when it goes over 359 degrees ans reset to 0, otherwise CRASH


or just ''and'' the value with 359

i.e.

xpos -= cos[heading & 359]*distance;
hey cool!
I''ve seen "&" used this way before, I didn''t know exactly what it did..

"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
Advertisement
>Go back X amount from the origin and then spin around it, while
>constantly looking at the origin ?

glRotatef(spinamount,0,1,0);
glTranslatef(0,0,-X);

wow pretty complicated.
so u want to pull of that effect where the game pauses ase u rotate around an object and the keep goin?
quote: Original post by Jx

or just ''and'' the value with 359

i.e.

xpos -= cos[heading & 359]*distance;


Actually.. I believe the modulus operator is what you''re looking for here.. the AND operator will not achieve the effect you want.

  int heading;heading %= 360;  // this makes sure that: 0 <= heading < 360  


I hope that helps..

- Ian Perez (fett@willcomp.com) - "It is by will alone I set my mind in motion"
- Ian Perez (iperez.fett@verizon.net) - "It is by will alone I set my mind in motion"
what DOES the & operator do then?

life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)

This topic is closed to new replies.

Advertisement