![]() |
|
|||||||
| Developers' Corner General World Wind development. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
WWJ Consultant
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
|
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;
}
|
|
|
|
|
|
#2 |
|
WWJ Consultant
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
|
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;
}
(te = terrain elevation under the camera target) ![]() Last edited by patmurris; 05-06-2007 at 09:09 PM. Reason: added diagram and title |
|
|
|
|
|
#3 |
|
Cosmic Overlord
Join Date: Oct 2004
Location: United Kingdom
Posts: 2,362
|
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 |
|
|
|
|
|
#4 |
|
WWJ Consultant
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
|
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. |
|
|
|
|
|
#5 | |
|
Super Member
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
|
Quote:
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. |
|
|
|
|
|
|
#6 | |
|
What?
Join Date: Apr 2005
Location: San Francisco, California
Posts: 2,464
|
Quote:
![]() 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. |
|
|
|
|
|
|
#7 |
|
Super Member
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
|
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. |
|
|
|
|
|
#8 |
|
WWJ Consultant
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
|
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 :
Let me know if that works as advertised ![]() |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Aug 2005
Posts: 317
|
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 |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |