c++ - How to move the position of a calculated circle? -
the situation have working method correctly calculates circumference. each position within circumference, stored within array of structs. camera position moves along circle depending on position within array. each element of array holds x,y , z values of position within 3d space.
the problem: position of circle seems located @ x:0,y:0,z:0 radius of 3 need @ location within 3d space (x:10,y:35,z:20) radius of 3.
my struct:
typedef struct { float x; float y; float z; } circle; circle loop[600] = {0};
my method calculates circle:
void calccircle() { (int = 0; < 599 ; i++) { loop[i].x = radius * sin(i/100.0); loop[i].y = 10; loop[i].z = radius * cos(i/100.0); } }
simply add offset calculations, eg center @ 10,35,20
...
const double pi = 3.1415926535; void calccircle() { (double = 0; < 2*pi ; i+=pi*2/600) { loop[i].x = 10 + radius * sin(i/2*pi); loop[i].y = 35; loop[i].z = 20 + radius * cos(i/2*pi); } }
note example isn't centered @ 0,0,0
@ 0,10,0
- if still want camera 10 above, add additional 10 y
value.
also, it's more common provide center orbit , offsets camera rather pre-calculating n points. way, camera can move smoothly instead of between fixed points. stands, speed of orbit tied framerate can vary between devices.
finally, i've changed scaling of sin
/cos
describe 1 complete orbit in 600 steps.
Comments
Post a Comment