I'm trying to use a rotated pyramid to show a camera's "field of view". See screenshot of what I have so far (The blue dot represents the camera's location):
Here are the definitions of how WorldWind's Rigid Shape API defines the pyramid attributes (http://builds.worldwind.arc.nasa.gov...idShape.html):
Center Position of shape (Latitude/Longitude)
north-south axis length: Side 1 (L)
east-west axis length: Side 2 (W)
vertical axis length: Height of Pyramid (H)
Roll: Roll, Rotation about the north-south axis
Tilt: Pitch, Rotation about the east-west axis
Heading: Azimuth, rotation about vertical axis
I've got it working as expected when the camera is looking straight out. I am calculating a center position of the pyramid based on the camera's range.
I set the heading to 0 degrees, the roll to 90, and set the tilt in degrees to whatever direction I want the camera (and hence the pyramid) to face. This is what I'm showing in the screenshot.
What I'm struggling with now is how to show the field of view moving up and down as the camera tilts up and down (along with the FOV rotating around the axis). I'm not even sure what sort of geometric equations I need to be looking at for this. I've tried a bunch of guess and check sort of things with the code, but I can't find a pattern to set up a formula for this. My Geometry skills have not been used in a while, so any help is appreciated.
Here is some sample java code that shows what I am trying to do. The code currently draws the camera's FoV and rotates around the camera. When I try to set the roll to anything other than 90, things go haywire. What I would like is to be able to show the FOV tilting up and down.
Here are the definitions of how WorldWind's Rigid Shape API defines the pyramid attributes (http://builds.worldwind.arc.nasa.gov...idShape.html):
Center Position of shape (Latitude/Longitude)
north-south axis length: Side 1 (L)
east-west axis length: Side 2 (W)
vertical axis length: Height of Pyramid (H)
Roll: Roll, Rotation about the north-south axis
Tilt: Pitch, Rotation about the east-west axis
Heading: Azimuth, rotation about vertical axis
I've got it working as expected when the camera is looking straight out. I am calculating a center position of the pyramid based on the camera's range.
I set the heading to 0 degrees, the roll to 90, and set the tilt in degrees to whatever direction I want the camera (and hence the pyramid) to face. This is what I'm showing in the screenshot.
What I'm struggling with now is how to show the field of view moving up and down as the camera tilts up and down (along with the FOV rotating around the axis). I'm not even sure what sort of geometric equations I need to be looking at for this. I've tried a bunch of guess and check sort of things with the code, but I can't find a pattern to set up a formula for this. My Geometry skills have not been used in a while, so any help is appreciated.
Here is some sample java code that shows what I am trying to do. The code currently draws the camera's FoV and rotates around the camera. When I try to set the roll to anything other than 90, things go haywire. What I would like is to be able to show the FOV tilting up and down.
Code:
public class CameraFOV extends ApplicationTemplate { public static class AppFrame extends ApplicationTemplate.AppFrame { public AppFrame() { this.addCameraAndFOV(); } double direction = 45; protected void addCameraAndFOV() { double lat = 40; double lon = -120; final double alt = 20000; RenderableLayer layer = new RenderableLayer(); layer.setName("Camera"); final TacticalSymbol symbol = new MilStd2525TacticalSymbol( "SFSP-----------", Position.fromDegrees(lat, lon, alt)); TacticalSymbolAttributes tAttrs = new BasicTacticalSymbolAttributes(); tAttrs.setScale(.4); symbol.setAttributes(tAttrs); symbol.setValue(AVKey.DISPLAY_NAME, "Camera"); // Tool tip text. symbol.setShowLocation(false); layer.addRenderable(symbol); // Add the symbol layer to the World Wind model. this.getWwd().getModel().getLayers().add(layer); // Update the layer panel to display the symbol layer. this.getLayerPanel().update(this.getWwd()); layer = new RenderableLayer(); layer.setName("FOV"); // Create and set an attribute bundle. ShapeAttributes attrs = new BasicShapeAttributes(); attrs.setInteriorMaterial(Material.RED); attrs.setInteriorOpacity(0.4); attrs.setEnableLighting(true); attrs.setOutlineMaterial(Material.RED); attrs.setOutlineWidth(2d); attrs.setDrawInterior(true); attrs.setDrawOutline(true); final double verticalradius = 50000; final double nsradius = 15000; final double ewradius = 10000; LatLon initialFovPosition = Position.greatCircleEndPosition( symbol.getPosition(), Math.toRadians(direction + 90), verticalradius / Earth.WGS84_EQUATORIAL_RADIUS); final Pyramid pyramid = new Pyramid(Position.fromDegrees( initialFovPosition.getLatitude().degrees, initialFovPosition.getLongitude().degrees, alt), nsradius, verticalradius, ewradius); pyramid.setAltitudeMode(WorldWind.ABSOLUTE); pyramid.setAttributes(attrs); pyramid.setValue(AVKey.DISPLAY_NAME, "Camera FOV"); layer.addRenderable(pyramid); Thread rotatingThread = new Thread(new Runnable() { @Override public void run() { while (true) { direction += 5; LatLon updatedFovPosition = Position.greatCircleEndPosition( symbol.getPosition(), Math.toRadians(direction + 90), verticalradius / Earth.WGS84_EQUATORIAL_RADIUS); pyramid.setCenterPosition(Position.fromDegrees( updatedFovPosition.getLatitude().degrees, updatedFovPosition.getLongitude().degrees, alt)); pyramid.setHeading(Angle.fromDegrees(0)); pyramid.setRoll(Angle.fromDegrees(90)); pyramid.setTilt(Angle.fromDegrees(direction)); AppFrame.this.getWwd().redraw(); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); rotatingThread.start(); // Add the layer to the model and update the layer panel. insertBeforePlacenames(getWwd(), layer); this.getLayerPanel().update(this.getWwd()); } } public static void main(String[] args) { ApplicationTemplate.start("Camera FOV", AppFrame.class); } }
Comment