|
-
Feb 20th, 2003, 03:49 PM
#1
Thread Starter
Frenzied Member
spherical coordinates??? (to make a camera's 1st person view)
Ok i want to make a game in directx8 and everything works really nice up to now.. but i really want to try and creating a way to make a first person kind of view and zaei told me to look up spherical coordinates on google , so i did and read some stuff about it .. but it all looks like big mumbo jumbo to me.. i got good grades at maths but didnt ever cover those kind of things ... can anybody please help me with that? :S
-
Feb 20th, 2003, 10:00 PM
#2
Frenzied Member
For this application, all you are really interested in is coversion from spherical to cartesian coordinates. A point defined in spherical coordinates has 3 values, r, p, and t. r is the distance from the origin, p is the lattitude angle, t is the longitude angle. For looking around, you simply modify the p and t values of a spherical coordinate (the angles that define the direction you are looking). r will stay constant at 1. To conver, use this formula:
Code:
x = r * sin(p) * cos(t)
y = r * sin(p) * sin(t)
z = r * cos(t)
Z.
-
Feb 21st, 2003, 07:14 AM
#3
transcendental analytic
in games where your camera is fixed horizontally, enabled to rotate along its center (1st person view) or an arbitrary center (3rd persion view) along vertical axis (corresponding to angle t in code zaei posted) and vertically in your camera's pov around the center, that is axis normal to horizontal pov (corresponding to angle p in zaei's code). In in flightsims or spacesims you'd rahter not want your camera restricted this way, but be able to rotate freely around any axis so you use quaternions. For a rotated vector vrot of v around axis u you have
in flightsims or spacesims
vrot=(u.v)u + cos(theta)(v-(u.v)u)+sin(theta)(u x v)
theta is the angle to rotate, . here is scalar product and x is the vector product.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 21st, 2003, 10:19 AM
#4
Thread Starter
Frenzied Member
it is ment to be used for a first person shooter kinda look. but i cant seem to make it work correctly (zaei's code) it works a bit but it moves left and right when just adding 1 to the numbers :S cant seem to really let it work perfectly sigh
-
Feb 21st, 2003, 11:58 AM
#5
Frenzied Member
The values of p and t are in radians, so a full circle is 0..2pi, instead of 0..360.
Z.
-
Feb 21st, 2003, 02:27 PM
#6
Thread Starter
Frenzied Member
ok something is going wrong now :s it is only moving up a bit and then down again instead of going in a circle am sure i am doing something wrong :S
-
Feb 21st, 2003, 02:29 PM
#7
Frenzied Member
Post some code snippets =)
Z.
-
Feb 21st, 2003, 02:30 PM
#8
Thread Starter
Frenzied Member
ok hangon please stay here :P
-
Feb 21st, 2003, 02:32 PM
#9
Thread Starter
Frenzied Member
key down
VB Code:
Case 201 ' page up
t = t + 0.1
player.lookatx = r * Sin(p) * Cos(t)
player.lookaty = r * Sin(p) * Sin(t)
player.lookatz = r * Cos(t)
Case 209
t = t - 0.1 ' page down
player.lookatx = r * Sin(p) * Cos(t)
player.lookaty = r * Sin(p) * Sin(t)
player.lookatz = r * Cos(t)
Every loop it does this
VB Code:
engine_d3d.camera_position player.x, player.y, player.z
engine_d3d.camera_lookat player.lookatx, player.lookaty, player.lookatz
which is a link to this in the dll
VB Code:
Public Sub camera_position(x As Single, y As Single, z As Single)
camera.posx = x
camera.posy = y
camera.posz = z
End Sub
Public Sub camera_lookat(x As Single, y As Single, z As Single)
camera.atx = x
camera.aty = y
camera.atz = z
End Sub
the code it really takes place
VB Code:
D3DXMatrixLookAtLH matView, MakeVector(camera.posx, camera.posy, camera.posz), MakeVector(camera.atx, camera.aty, camera.atz), MakeVector(0, 1, 0)
D3DDevice.SetTransform D3DTS_VIEW, matView
D3DDevice.SetTransform D3DTS_WORLD, matWorld
-
Feb 21st, 2003, 02:42 PM
#10
Frenzied Member
Ok, the lookat coordinate is going to be the converted spherical coordinate added to the player's position. Also, if you want to look up and down, modify the p value, not the t value. t is for rotation around the y axis.
Z.
-
Feb 21st, 2003, 02:51 PM
#11
Thread Starter
Frenzied Member
er so how should i put in the program? veye , vat and vup what are they precisely :S
-
Feb 21st, 2003, 03:36 PM
#12
Frenzied Member
veye == camera position
vat == where camera is looking
vup == vector that is pointing "up"
You have the matrix generation correct, just not how you calculate your lookat coordinate. It should be the spherical coordinate plus the camera position (since the spherical coordinate is defined in relation to the origin, you want it in relation to your camera position).
Z.
-
Feb 21st, 2003, 03:39 PM
#13
Thread Starter
Frenzied Member
ok i am feeling more stupid every time you post :S it might be the fact that i am dutch and i dont get the level of the words .... but that high calculation of maths wasnt that great :S.. can you help me with an example? also i have to give the line a D3dvector but how can i convert that to a correct vector then or something ? :S
-
Feb 23rd, 2003, 03:31 AM
#14
Fanatic Member
Originally posted by Zaei
Code:
x = r * sin(p) * cos(t)
y = r * sin(p) * sin(t)
z = r * cos(t)
I think the formula for z is wrong. It should be r * cos(p). This formula is valid only for a right handed coordinate system (with the y axis pointing into the screen and the z axis pointing up).
For a left handed coordinate system (in which most games are, I think), the values for y and z should be swapped.
-
Feb 23rd, 2003, 05:59 PM
#15
Frenzied Member
Originally posted by riis
I think the formula for z is wrong. It should be r * cos(p). This formula is valid only for a right handed coordinate system (with the y axis pointing into the screen and the z axis pointing up).
For a left handed coordinate system (in which most games are, I think), the values for y and z should be swapped.
ooh, good eye =). It should be cos(p).
Z.
-
Feb 26th, 2003, 02:30 PM
#16
Thread Starter
Frenzied Member
ok you figured that out :P but err still i dunno how to apply these values. since you told me i shouldnt change it to a d3dvector but that is the only thing it accepts in the position part , what do i have to aply the values too? :S
-
Feb 26th, 2003, 03:27 PM
#17
Frenzied Member
position == player position
lookat == player position + converted spherical coordinates.
Imagine a big sphere around yourself. Any direction you look, you are loking at a point on that sphere, given by 2 angles. Howver, the center of that sphere is at your position, NOT the origin, so you need to move the sphere (adding the players position)
Z.
-
Feb 27th, 2003, 06:03 AM
#18
Fanatic Member
Those angles are equivalent with latitude and longitude (breedte- en lengtegraad in dutch) on a globe. You (actually your eyes) are at the center of the globe, not somewhere on the outside. So, you look onto the inside of the globe's surface.
-
Feb 28th, 2003, 02:51 PM
#19
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|