walking on a sphere
Hi !
So my problem is to find out how to walk on that spherical engine of mine...
Here is how I''m trying to do this for now, but it doesn''t work. I tried another solution earlier but it was worst.
My camera keep the same place ever and only the sphere is rotating.
When the character moves, the sphere is rotating on the x axis and on the y axis ( y here is the vertical ); depending on the angle of vision ( stored from mouse motions).
Based on the amount of motion already done on one of the two axis I keep two values corresponding to latitude ( for x axis rotations ) and longitude ( for y axis rotations ).
It seems to work but I''m not totally sure... The first main problem comes when I want my camera to face ahead again, after the movement.
I rotate the sphere on the z axis, and sometimes it works fine. but other times it doesn''t.
Well, the other problem :
I''m keeping latitude and longitude for several purposes ( knowing the height value of the current position for example ).
When one goes too far on longitudes ( for example + 181°) , it just restarts at longitude - 179 ° and achieves its trip around the world...
Going too far in latitudes is far more problematic...
I have to change longitudes by adding 180° (right ?) change direction...
I can''t fix it.
If anyone has already done this or want to help you''re welcome.
Thank you !
You''re aim is to keep the character on the center of the screen as you rotate sphere while walking around, right?
So it''s easier to move your camera and character than rotate your sphere. I think you should use spherical coordinates system (a.k.a polar) for both character and camera.
spherical(r,theta,phi) to cartesian(x,y,z) :
x = r * cos(phi) * cos(theta)
y = r * cos(phi) * sin(theta)
z = r * sin(phi)
where :
r is :
- for character : sphere''s radius
- for camera : sphere''s radius + camera''s altitude
theta is longitude (radians)
phi is latitude (radians)
The last thing you should consider is that your camera always points to center of sphere (easy...).
That''s all for the moment...
I know that I don''t know nothing... Operation Ivy
So it''s easier to move your camera and character than rotate your sphere. I think you should use spherical coordinates system (a.k.a polar) for both character and camera.
spherical(r,theta,phi) to cartesian(x,y,z) :
x = r * cos(phi) * cos(theta)
y = r * cos(phi) * sin(theta)
z = r * sin(phi)
where :
r is :
- for character : sphere''s radius
- for camera : sphere''s radius + camera''s altitude
theta is longitude (radians)
phi is latitude (radians)
The last thing you should consider is that your camera always points to center of sphere (easy...).
That''s all for the moment...

I know that I don''t know nothing... Operation Ivy
I know that I don't know nothing... Operation Ivy
quote:
Original post by BloodScourge
You''re aim is to keep the character on the center of the screen as you rotate sphere while walking around, right?
The last thing you should consider is that your camera always points to center of sphere (easy...).
NepenthesRajah, are these assumptions correct? It would help a lot if you could give an explicit example of what you are trying to achieve so that we could offer a solution.
Could you include please:
1) An example starting position
2) An example action
3) An example ending position
4) What the camera should do given this action
Other questions:
Is the camera fixed on the character the whole time, or on a point on the sphere?
Can the camera pan around?
Does the sphere move in world coordinates (so that if the camera remains pointing at the same point in world space, the world appears to move in the window frame)?
Cheers,
Timkin
Thank you for answers !
Some details :
I''m working in first person view.
For spherical coordinates, I would like to use them. And I''m trying to find a system for them to work.
I will describe what happens :
In spherical coords :
a. I compute the new latitude and new longitude based on the angle given by mouse rotation. and given what I called horizontal velocity which is horizontal considering the sphere surface.( this is how I do on a plane map.)
example :
velocity=1;
angle = 45;
latit = sin(angle*piover180) * velocity;
longit= cos(angle*piover180) * velocity;
(here both = 0.707)
then I add latit to the current latitude and same for current longitude.
Is this biased ?
I think I should use a sort of factor for the velocity either for latit or longit computation. because when I come close to a pole, meridians are closer relative to each other and I''m sort of sucked into the pole. ( the same angle of 45° will not have the same direction close to the equator than close to the pole.
All the above is based on the fact that at an angle of 0° of mouse character will go North.
(I''m no more sure if I did right with this...)
b. I then figure the x,y, and z coordinates.
Another problem comes when I pass a pole.
latitude pass over 90°... Obviously sin and cos can handle this but unfortunately my heightmap array can''t. and I need to know where am I, in reliable sphere coordinates.
In character never moves solution :
I compute the latitude and longitude motion same way as above.
Instead of figuring where the character should end, I directly rotate the sphere inversely.
I think the two solutions are very close.
Examples :
1. start at 0,0. let''s say : equator, greenwich meridian.
2. going 45° north/east
this makes me going north in spiral until I got through the pole and inverse spiral other side.
After I passed the pole the mouse orientation is inversed.
I think this can be right except for inverse mouse. I looked on a terrestrial globe and it is understandable.
But I want to go ahead.
Other example, starting at pole what if I go straight West ?
With my system as it is, I will not move because at pole all the longitudes are actually the same point...
finally after writing this message I''m convinced my problem comes from how I compute the new coords depending on velocity.
Can you help me here ?
Some details :
I''m working in first person view.
For spherical coordinates, I would like to use them. And I''m trying to find a system for them to work.
I will describe what happens :
In spherical coords :
a. I compute the new latitude and new longitude based on the angle given by mouse rotation. and given what I called horizontal velocity which is horizontal considering the sphere surface.( this is how I do on a plane map.)
example :
velocity=1;
angle = 45;
latit = sin(angle*piover180) * velocity;
longit= cos(angle*piover180) * velocity;
(here both = 0.707)
then I add latit to the current latitude and same for current longitude.
Is this biased ?
I think I should use a sort of factor for the velocity either for latit or longit computation. because when I come close to a pole, meridians are closer relative to each other and I''m sort of sucked into the pole. ( the same angle of 45° will not have the same direction close to the equator than close to the pole.
All the above is based on the fact that at an angle of 0° of mouse character will go North.
(I''m no more sure if I did right with this...)
b. I then figure the x,y, and z coordinates.
Another problem comes when I pass a pole.
latitude pass over 90°... Obviously sin and cos can handle this but unfortunately my heightmap array can''t. and I need to know where am I, in reliable sphere coordinates.
In character never moves solution :
I compute the latitude and longitude motion same way as above.
Instead of figuring where the character should end, I directly rotate the sphere inversely.
I think the two solutions are very close.
Examples :
1. start at 0,0. let''s say : equator, greenwich meridian.
2. going 45° north/east
this makes me going north in spiral until I got through the pole and inverse spiral other side.
After I passed the pole the mouse orientation is inversed.
I think this can be right except for inverse mouse. I looked on a terrestrial globe and it is understandable.
But I want to go ahead.
Other example, starting at pole what if I go straight West ?
With my system as it is, I will not move because at pole all the longitudes are actually the same point...
finally after writing this message I''m convinced my problem comes from how I compute the new coords depending on velocity.
Can you help me here ?
I made vertex shader which is mapping parallel planes to concetring spheres.For example:when you directly move with point in plane from point [1;1;z] to [0;0;z](z-axis is oriented upwards,x-axis to the front,y-axis to the right,i use right-handed system) then it is mapped to the part of meridian,when you move on concetric circles C1 in this plane,then this movement is mapped on the circle C2 which is on the sphere and which have same radius like C1.
So if you move with mouse from downwards to upwards then you have to move the object from the front to the back in the direction of unit vector i by transform matrix.
And,when you move from the left to the right with mouse,then rotate the object arround z-axis.
If you want ,i may send you .vsh.
Sorry for my bad english
So if you move with mouse from downwards to upwards then you have to move the object from the front to the back in the direction of unit vector i by transform matrix.
And,when you move from the left to the right with mouse,then rotate the object arround z-axis.
If you want ,i may send you .vsh.
Sorry for my bad english
ARGGGHHHHH!!!! I posted a huge solution to your problem yesterday and it''s not here!!! Any other moderator want to own up to deleting it or are we having problems with the DB again???
Timkin
Timkin
Timkin, I''m sorry for your work and the time it has involved. Would you sum it up ?
Alex, I think this is aproximately what I might be doing.
But I encounter problems when I do a combined motion, say front + right. I''m not sure of the ammount of rotation on each axis, and I end with weird oblique motions if I do it 1:1.
Thanks for interest.
Alex, I think this is aproximately what I might be doing.
But I encounter problems when I do a combined motion, say front + right. I''m not sure of the ammount of rotation on each axis, and I end with weird oblique motions if I do it 1:1.
Thanks for interest.
I did not tested it yet...
wop.vsh:
; c0-c3 - transormation matrix
; c4-c7 - view+projection matrix
; c10 - first 4 taylor coefficients for sin(x)
; c11 - first 4 taylor coefficients for cos(x)
; r0.x -x-ova v PS
; r0.y -y-ova v PS
; r0.z -z-ova v PS = ro
; r0.w -
; c13.x - PI/2
; c13.y - Rmax=polednik...
; c13.z - Rz
; c13.w - 1
; r1.x - cos(alfa)
; r1.y - sin(alfa)
; r1.z - d=sqrt(x^2+y^2),
; r1.w - fi
; r2,r3,r4- temp
;********************************************
vs.1.0
;data from LH to RH:
mov r0.yzw,v0.xyw
mov r0.x,-v0.z
;world transformation
m4x4 r0,ro,c0
;radius of the sphere
add r0.z,r0.z,c13.z
mul r1.xy,r0.xy,r0.xy
add r1.z,r1.x,r1.y ; x^2+y^2
rsq r1.z,r1.z
mul r1.x,r1.z,r0.x ; r1.x=sin(alfa)
mul r1.y,r1.z,r0.y ; r1.y=cos(alfa)
rcp r1.z,r1.z ; r1.z=d=distance from
origin in 0xy plane
rcp r2.x,c13.y
mul r2.y,r2.x,r1.z ;1/Rmax * d
mul r1.w,r2.y,c13.x ;r1.w=fi=1/Rmax * d * pipul
;first 4 values for sin a cos series
mov r2.x,c13.w ;fi^0
mov r3.x,r1.w ;fi^1
mul r2.y,r3.x,r3.x ;fi^2
mul r3.y,r2.y,r3.x ;fi^3
mul r2.z,r3.y,r3.x ;fi^4
mul r3.z,r2.z,r3.x ;fi^5
mul r2.w,r3.z,r3.x ;fi^6
mul r3.w,r2.w,r3.x ;fi^7
mul r2,r2,c11 ;cos ~ 1 -fi^2 fi^4 -fi^6
dp4 r2.x,r2,c13.w ;r2.x= 1 - 1/2! * fi^2 + 1/4! * fi^4 - 1/6! * fi^6 ~ cos(fi)
mul r3,r3,c10 ;sin
dp4 r3.x,r3,c13.w ;r3.x=sin(fi)
mul r0.x,r0.z,r3.x ;r0.x=ro*sin(fi)
;uz jsme zase zpatky...ufffff
mul r0.y,r0.x,r1.y ;r0.y=ro*sin(fi)*cos(alfa)
mul r0.x,r0.x,r1.x ;r0.x=ro*sin(fi)*sin(alfa)
mul r0.z,r0.z,r2.x ;r0.z=ro*cos(fi)
;transformace view+proj
m4x4 oPos,r0,c4
wop.vsh:
; c0-c3 - transormation matrix
; c4-c7 - view+projection matrix
; c10 - first 4 taylor coefficients for sin(x)
; c11 - first 4 taylor coefficients for cos(x)
; r0.x -x-ova v PS
; r0.y -y-ova v PS
; r0.z -z-ova v PS = ro
; r0.w -
; c13.x - PI/2
; c13.y - Rmax=polednik...
; c13.z - Rz
; c13.w - 1
; r1.x - cos(alfa)
; r1.y - sin(alfa)
; r1.z - d=sqrt(x^2+y^2),
; r1.w - fi
; r2,r3,r4- temp
;********************************************
vs.1.0
;data from LH to RH:
mov r0.yzw,v0.xyw
mov r0.x,-v0.z
;world transformation
m4x4 r0,ro,c0
;radius of the sphere
add r0.z,r0.z,c13.z
mul r1.xy,r0.xy,r0.xy
add r1.z,r1.x,r1.y ; x^2+y^2
rsq r1.z,r1.z
mul r1.x,r1.z,r0.x ; r1.x=sin(alfa)
mul r1.y,r1.z,r0.y ; r1.y=cos(alfa)
rcp r1.z,r1.z ; r1.z=d=distance from
origin in 0xy plane
rcp r2.x,c13.y
mul r2.y,r2.x,r1.z ;1/Rmax * d
mul r1.w,r2.y,c13.x ;r1.w=fi=1/Rmax * d * pipul
;first 4 values for sin a cos series
mov r2.x,c13.w ;fi^0
mov r3.x,r1.w ;fi^1
mul r2.y,r3.x,r3.x ;fi^2
mul r3.y,r2.y,r3.x ;fi^3
mul r2.z,r3.y,r3.x ;fi^4
mul r3.z,r2.z,r3.x ;fi^5
mul r2.w,r3.z,r3.x ;fi^6
mul r3.w,r2.w,r3.x ;fi^7
mul r2,r2,c11 ;cos ~ 1 -fi^2 fi^4 -fi^6
dp4 r2.x,r2,c13.w ;r2.x= 1 - 1/2! * fi^2 + 1/4! * fi^4 - 1/6! * fi^6 ~ cos(fi)
mul r3,r3,c10 ;sin
dp4 r3.x,r3,c13.w ;r3.x=sin(fi)
mul r0.x,r0.z,r3.x ;r0.x=ro*sin(fi)
;uz jsme zase zpatky...ufffff
mul r0.y,r0.x,r1.y ;r0.y=ro*sin(fi)*cos(alfa)
mul r0.x,r0.x,r1.x ;r0.x=ro*sin(fi)*sin(alfa)
mul r0.z,r0.z,r2.x ;r0.z=ro*cos(fi)
;transformace view+proj
m4x4 oPos,r0,c4
quote:
Original post by Timkin
ARGGGHHHHH!!!! I posted a huge solution to your problem yesterday and it''s not here!!! Any other moderator want to own up to deleting it or are we having problems with the DB again???
Timkin
I feel your pain...I''ve seen this behavior from time-to-time, and my guess is that it is DB problems. Again.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
quote:
Original post by NepenthesRajah
Timkin, I''m sorry for your work and the time it has involved. Would you sum it up ?
Bascially I showed the derivation of the 3 equations relating the 3D Cartesian velocities to the 3D polar velocities and then explained how you could either treat your user input as polar velocites and compute the appropriate Cartesian velocties, or you could treat the user inputs as a linear combination of Cartesian velocites and solve for the polar velocities. I''m a bit flat out today and going away for the weekend, however, if you still haven''t solved your problem by Monday I''ll try and find time to rewrite my solution.
Cheers,
Timkin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement