Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Camera roll and dbPointCamera

Author
Message
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 27th May 2009 23:42
When I use dbPointCamera it levels itself (roll) with the X-Z plane.

Anyone have ideas on how I might disable/modify this, so in a space environment, you don't have the obvious rolling whenever your view crosses the Y axis (up or down)?

dbRollCamera just adds a specified angle to the existing behaviour, so not sure how I could take advantage of that.

I am thinking I want to somehow glue the camera "UP" direction with an object's local "UP" direction (eg. the player ship), or better, somewhere to the object's Y-Z plane (so only the roll is clamped). Anyone know how I might do that?

Thanks, you guys have been great help in past!
DannyE
15
Years of Service
User Offline
Joined: 10th May 2009
Location:
Posted: 28th May 2009 00:10
I am thinking if you are creating a charector that the camera follows than couldn't you Create a variable like this?
float fCamera = dbObjectPositionZ ( 1 );

dbPointCamera ( ..., ..., fCamera );

I think it would work.
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 28th May 2009 01:29
@ DannyE

Not sure what you're getting at. I do already point the camera at my object position, but using dbPointCamera keeps the horizon always horizontal.

I realize now, all I need is a way for the camera to match the roll of my spaceship object, which is not always horizontal.

P.S. using dbSetCameraToObjectOrientation will match the roll but I still want to look at the object rather than the direction of the object. Anyone know the math I need to point this camera?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th May 2009 23:51
Let's see if I understand correctly: you have a spaceship which is going in any direction in space, rolling in the meantime, and you want the camera to follow from a certain distance, looking AT the object, while matching the left-right roll of the ship?

Try this:



where idShip is the object ID of your spaceship, "angle" is how much you want the camera to "look down" on your ship, and "distance" (negative) is how much you want the camera to be behind the object.

Does that work?
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 29th May 2009 04:13
ARG... yeah your understanding is correct and this is a good solution, except for one thing. I still have a problem with dbSetCameraToObjectOrientation.

What I meant about pointing at the ship is because I do have position damping/spring code for the camera, so I want to point the camera at the ship even while it's still springing back behind the ship from some arbitrary angle. If I simply keep the spring and match the orientation the ship can slide off centre, and even out of view.

I started to try to make my own LookAt function, but without using Matrices I wasn't able to properly translate the direction vector back into XYZ angles for the camera, the resulting view is totally wonky. Sample of my code with problems in comments:



In the end, need a more powerful way to manipulate orientation, which is beginning to seem impossible with only axis-angles/Euler angles, so almost certain I will need to take up Matrices (or Quaternions), which I don't fully grasp, especially with the DGDK.

For anyone else following, I will probably be able to figure something out from DirectX Matrices here

http://www.dhpoware.com/demos/d3dCamera1.html

but haven't tackled it yet. Let me know if you do...
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 29th May 2009 11:28
Couldn't you use dbCurveAngle(int,int,int); ? It provides a nice smooth curve to a specified angle


Website coming soon!!
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 29th May 2009 16:20
Well, that might help me with a spring/damping for the camera direction, but it's not my issue. I want to look exactly at the ship at all times, without damping, but with a special roll/orientation. My camera position on the other hand is already damped and works fine.

Thanks though, I didn't know about that function.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 29th May 2009 19:15
@endre3000

Take a look at this site:
http://www.euclideanspace.com/maths/geometry/transform/index.htm

It has almost everything you will ever need to know about matrices, quaternions, complex number, etc. and more importantly how they relate to geometry, and how you can use them in your programs.

endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 30th May 2009 10:56
@Diggsey
Yes thanks, I am on that site frequently these days.

Well this is turning out to be an interesting project. For whatever reason, I have kept mining for a solution using Euler angles and trigonometry. I have made a lot of progress but am stuck at a new point. I have the camera rolling properly, but only through half the range.

Basically it comes down to taking the the dot product of two vectors, one is the "camera up" and the other is a projection of the "ship's up" onto the camera's/screen plane. From this I can get the angle between them, thus the angle to roll the camera, by taking the inverse cos (arccos).



Now my only problem is that acos() returns only between 0-180 degrees, but of course the roll is needed from anywhere between -180 to 180 (or 0-360) degrees. In real life we use the right-hand rule or visually inspect if the rotation is positive or negative, but in code and in math... how can I determine this here?

When I was tackling a similar problem before with arctan I was able to devise the quadrant from the x and y components and apply the CAST rule. But here the coordinate system is no longer neat, it is an arbitrary plane so looking at x,y,z components isn't the same... Help?
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 30th May 2009 11:37
Could you not just keep a track of the roll, point the camera first and then roll it using the stored value?

endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 30th May 2009 19:35
@ jezza

Yeah, that is what I do, the whole problem is finding the proper roll angle.

For anyone following, I managed to solve my last problem. I found a way to determine which direction to apply the roll angle by taking another dot product of the projection of the "ship's up" vector with the "camera right" vector. From this I can tell which side of the "camera up" vector the projection angle is on.



Thanks for working through with me, sometimes it helps to also just write everything out! Cheers.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 1st Jun 2009 11:47
Congratulations for having worked it out! Sorry that I couldn't help more, the math is way too complicated for me, but I'm glad that you finally solved the problem.
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 2nd Jun 2009 20:37
Thanks! I really would like to help others understand these problems more too. Maybe it can be of some benefit if I try to explain it very briefly from a high level, then give links for the in depth reference.


The problem can be though of as flattening (projecting) a given line onto a given plane, then finding the angle it makes on the plane.

To do this, we fist:
1) Take the cross product of the line (well, vector) with the normal of the plane. This gives us a vector that is guaranteed to be on the plane.
2) Then, we can take a cross product of the new vector with the normal again, and it gives us a line also on the plane but in the direction (projection) of our problem line.
3) We find the angle it makes with your reference "up direction" on the plane using the dot product.
4) Now we still can't be sure if this angle means "to the left" or "to the right" of our up, so we take another dot product of the vector with your reference "right direction", and from the two answers we can tell the true direction.


To fully understand what I needed to do, these two specific pages should be all you need, if not a good start:
http://www.euclideanspace.com/maths/geometry/elements/plane/lineOnPlane/index.htm
http://www.euclideanspace.com/maths/geometry/elements/line/projections/index.htm

Good luck to everyone.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 3rd Jun 2009 11:39
Great job, I've been watching this thread, with interest, but I didn't had the answers.

I think I fully understand the problem, that is, the Y axis being the default 'zenith' for the DGDK camera.

If this procedure allows to use a runtime defined 'zenith', well that is great.
If it just overrides the auto-roll on the camera, also great.

A very valuable code snippet. I'll make some room in my shedule to test this
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 16th Jun 2009 12:30 Edited at: 16th Jun 2009 12:31
Ajem, I'm sorry because I had a workaround and I didn't rememeber
Now I have revised my code, and I use an auxiliar dummy object, that is rotated with local rotations funtions (turn & pitch), then just apply dbSetCameraToObjectOrientation

Login to post a reply

Server time is: 2024-11-25 08:19:48
Your offset time is: 2024-11-25 08:19:48