I have created a behavior that allows me to draw a rectangle on the game surface and then send the coordinates of the rectangle to the game. I would like to zoom the camera such that the view limits become the rectangle. I am not sure exactly
how to describe what I am trying to accomplish, except to refer to it as Zoom To Area. In a sense, the rectangle should fill my viewport.
I have tried several ways to accomplish this. The one that I have tried most recently is to set the target to be the center of the rectangle and then to test the coordinates of the corners of the rectangle using Camera.IsInView(Coordinate).
This will work. However, what is failing is that I am using Ray/PickRay. In order to use IsInView, I am trying to get the corner coordinates Viewport.GetNodeAtPosition and the nodes in my scene. GetNodeAtPosition is returning the same node
for all three calls. here is what I am doing:
double diffX = (bottomRight.X - topLeft.X) / 2.0;
double diffY = (bottomRight.Y - topLeft.Y) / 2.0;
Point halfWay = new
Point(topLeft.X + diffX, topLeft.Y + diffY);
Ray centerRay = Viewport.GetPickRay((int)halfWay.X, (int)halfWay.Y);
var centerNode = Viewport.GetNodeAtPosition((int)halfWay.X, (int)halfWay.Y);
Ray upperRay = Viewport.GetPickRay((int)topLeft.X, (int)topLeft.Y);
var upperNode = Viewport.GetNodeAtPosition((int)topLeft.X, (int)topLeft.Y);
Ray lowerRay = Viewport.GetPickRay((int)bottomRight.X, (int)bottomRight.Y);
var lowerNode = Viewport.GetNodeAtPosition((int)bottomRight.X, (int)bottomRight.Y);
BottomRight and TopLeft are 2D Screen points. When these lines execute, centerNode, lowerNode and upperNode are all identical, no matter how far apart the points are.