World Wind Forums

Go Back   World Wind Forums > WorldWind .Net Development > Developers' Corner

Developers' Corner General World Wind development.

Reply
 
Thread Tools Display Modes
Old 05-06-2007, 03:35 AM   #1
patmurris
WWJ Consultant
 
patmurris's Avatar
 
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
Question Fixing the Camera : help w math please

I'm in the process of fixing up the WW camera so that it reports correct altitude and distance, and maybe doesnt go underground too often.

I managed to decipher most of the Camera.cs and WorldCamera.cs code and could fix up most of the faulty behavior... Bull is testing, and things work better so far.

However, i still dont understand the math used by the actual code to compute the camera distance from the target, knowing its altitude and the tilt angle.

Here is the camera logic as i understand it :



Here is the code i dont understand (from Camera.cs):

Code:
        protected void ComputeDistance( double altitude, Angle tilt )
        {
            double cos = Math.Cos(Math.PI-tilt.Radians);
            double x = _worldRadius*cos;
            double hyp = _worldRadius+altitude;
            double y = Math.Sqrt(_worldRadius*_worldRadius*cos*cos+hyp*hyp-_worldRadius*_worldRadius);
            double res = x-y;
            if(res<0)
                res = x+y;
            _distance = res;
        }
If anyone understand it, please point me in the right direction.
__________________
My World Wind Java Blog & WW.net Plugins page
patmurris is offline   Reply With Quote
Old 05-06-2007, 05:52 AM   #2
patmurris
WWJ Consultant
 
patmurris's Avatar
 
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
Default Distance to target with Altitude and Tilt

Thats what i think it should be :
Code:
        protected void ComputeDistance(double altitude, Angle tilt)
        {
            double hyp = _worldRadius + altitude;
            double a = (_worldRadius + curCameraElevation) * Math.Sin(tilt.Radians);
            double b = Math.Sqrt(hyp * hyp - a * a);
            double c = (_worldRadius + curCameraElevation) * Math.Cos(tilt.Radians);
            _distance = b - c;
        }
Note : curCameraElevation is based on te * vertical exaggeration
(te = terrain elevation under the camera target)

__________________
My World Wind Java Blog & WW.net Plugins page

Last edited by patmurris; 05-06-2007 at 09:09 PM. Reason: added diagram and title
patmurris is offline   Reply With Quote
Old 05-07-2007, 08:36 PM   #3
bull
Cosmic Overlord
 
bull's Avatar
 
Join Date: Oct 2004
Location: United Kingdom
Posts: 2,362
Default

I asked Norman on irc to check this post, here is the reply

<+nhv> Bull I don't understand the problem distance is just EYE-TARGET where XYZ of EYE and TARGET LatLonElevation can be found by substituting appropriately for R http://mathworld.wolfram.com/SphericalCoordinates.html
<+nhv> R=EarthRadius + elevation
__________________
Bull_[UK]

bull is offline   Reply With Quote
Old 05-07-2007, 09:54 PM   #4
patmurris
WWJ Consultant
 
patmurris's Avatar
 
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
Default

I dont know the EYE (camera) position... i'm trying to compute it !!!
As i mentioned twice in my above post, i try to compute the distance only knowing tilt and altitude.
__________________
My World Wind Java Blog & WW.net Plugins page
patmurris is offline   Reply With Quote
Old 05-08-2007, 12:25 AM   #5
nlneilson
Super Member
 
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
Default

Quote:
Originally Posted by patmurris View Post
I dont know the EYE (camera) position... i'm trying to compute it !!!
As i mentioned twice in my above post, i try to compute the distance only knowing tilt and altitude.
EYE (camera) position is a known position from the drawargs.

The LatLon of the camera are known values.
this.drawArgs.WorldCamera.Latitude.Degre es,
this.drawArgs.WorldCamera.Longitude.Degr ees,

The altitude of the camera is also a known value but the WW code is a bit confusing, most of the civilized world uses altitude as distance above mean sea level while WW uses altitude as distance above terrain.
The value for hyp in your drawing would be:
this.drawArgs.WorldCamera.AltitudeAboveT errain
+
drawArgs.WorldCamera.TerrainElevation
+
the world radius

Note that WW uses the semi major axis of the earth ellipse (WGS84) for the world radius and calculation for a sphere, which is close enough for playing horseshoes but is no ringer.

The camera tilt is in one plane so the calculations can be done in 2D but if a person wants to us 3D calculations they can to make their head hurt. That can be done by hitting ones head against a hard object.

The exaggeration of the drawing may make the problem look harder than it is, the earth including the highest mountains to scale is smoother then a pool ball .

Without a trial an error type of iteration to see if the terrain (TARGET) is in the path of the center of the camera view I do not know how the distance from the camera to a point on the terrain, such as a mountain, can be done, it will be interesting to see what someone comes up with.

Last edited by nlneilson; 05-08-2007 at 12:43 AM.
nlneilson is offline   Reply With Quote
Old 05-08-2007, 01:05 AM   #6
withak
What?
 
withak's Avatar
 
Join Date: Apr 2005
Location: San Francisco, California
Posts: 2,464
Default

Quote:
Originally Posted by nlneilson View Post
EYE (camera) position is a known position from the drawargs.

The LatLon of the camera are known values.
this.drawArgs.WorldCamera.Latitude.Degre es,
this.drawArgs.WorldCamera.Longitude.Degr ees,
Where do you think those numbers come from?

Of course all of those things are "known" from outside of the camera class, Patrick is fixing the calculations that go on inside of the camera.

Last edited by withak; 05-08-2007 at 01:08 AM.
withak is offline   Reply With Quote
Old 05-08-2007, 03:02 AM   #7
nlneilson
Super Member
 
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
Default

Quote:
Originally Posted by withak View Post
Where do you think those numbers come from?
Will be interested to find where the Lat, Lon etc for the camera position comes from if it is different from where I think it comes from.

When WW starts the LatLon-etc is from WorldSettings.cs.
Any change of camera position is done "manually" by panning, zooming, by an html file, momentum or whatever. The only "calculation" for this is adding, subtracting or whatever to get the desired LatLon-etc for the camera.

From the LatLon-etc that is set/changed the graphics to be drawn and how it is to be drawn is calculated and displayed.

By stepping thru WW in debug this seems to be how it is done, after the LatLon-etc of the camera is "set" (in drawArgs) then the graphics are drawn accordingly.
Otherwise it would seem to be putting the cart before the horse.

The question from the original post is for the distance from the camera to a target. For a known and predictable surface such as a sphere or an ellipse this can be done directly. Where the terrain varies in elevation is the real problem, where is the intersection or target at the varying elevation.

The measure plugin, which I have not looked at the code yet, that draws a line on the surface or at the elevation of the terrain may give an indication of what/how this can be done.

Last edited by nlneilson; 05-08-2007 at 03:09 AM.
nlneilson is offline   Reply With Quote
Old 05-08-2007, 05:25 AM   #8
patmurris
WWJ Consultant
 
patmurris's Avatar
 
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
Arrow New camera version commited

Forget about how to do it... i could sort it out from the first diagram and a new version of the camera code is being tested right now (#WW802 SVN Trunk).

My question was about understanding what the original code was computing... which doesnt fit the diagram. Just curious.

About the new camera code :
  • Altitude is now the 'civilized world' camera elevation above sea level.
  • Distance is to the camera target - on the globe surface (elevation zero) or at the terrain level depending on ElevateCameraLookAtPoint in the Options (default is terrain level).
  • When colliding with the terrain, the camera will not 'bounce back' as before, but tilt back toward the vertical - and if not enough, it will put a bit more distance between the camera and the target, just enough to be above ground.
Also, a new camera setting option allows to go 'below sea level', but many things dont work anymore then. So this is still experimental, until WW can support negative altitudes for the camera.

Let me know if that works as advertised
__________________
My World Wind Java Blog & WW.net Plugins page
patmurris is offline   Reply With Quote
Old 05-08-2007, 02:28 PM   #9
nigel_ht
Senior Member
 
Join Date: Aug 2005
Posts: 317
Default

If you have the time could you add a mode so that we can change the camera to look in any direction? Like stand on the ground and look around, even up at the sky? DDH mentioned this would be simple to do but I never looked at the code.

When below sea level I guess we can turn off a lot of things that are broken (sky, etc).

Nigel
nigel_ht is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
WW 1.4 : Fixing broken plugins (renderable) patmurris Add-on & Script Development 5 05-11-2007 04:07 PM
Camera with spline animation Unregistered Suggestion Box 1 03-08-2007 01:06 AM
Camera Overshoot Fix webbhead Suggestion Box 0 08-17-2006 01:20 AM
How can i move the camera ? Ghost Rider Developers' Corner 6 04-11-2006 07:09 AM
few suggestions (keyframing, shading, camera...) Jakub Suggestion Box 3 01-27-2005 08:20 PM


All times are GMT +1. The time now is 04:38 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.