Issues Inserting Camera

In my simulation, I insert a camera into my robot. The problem is that when you insert a camera into an entity, and then insert that entity into a another entity, then view from the camera looks strange. If the entity you inserted the camera into is a top-level entity (has no Parent), then there is no problem. I put together a simple example using two boxes and a camera to illustrate the problem

The following code will produce the scene below from the new camera.

Code Snippet

SingleShapeEntity parentBox =newSingleShapeEntity(newBoxShape(

newBoxShapeProperties(

100,// mass in kilograms.

newPose(),// relative pose

newVector3 (2, 2, 2))),// dimensions

newVector3(0, 1, -10));

parentBox.State.Name ="ParentBox";

SingleShapeEntity childBox =newSingleShapeEntity(newBoxShape(

newBoxShapeProperties(

100,// mass in kilograms.

newPose(),// relative pose

newVector3(3, 3, 3))),// dimensions

newVector3(0, 1.5f, 0));

childBox.State.Name ="ChildBox";

CameraEntity camera =newCameraEntity(640, 480);

camera.State.Name ="TheCamera";

camera.State.Pose.Position =newVector3(0, 1.5f, 0);//on top of child box

childBox.InsertEntity(camera);

SimulationEngine.GlobalInstancePort.Insert(childBox);

SimulationEngine.GlobalInstancePort.Insert(parentBox);

http://farm2.static.flickr.com/1085/1403916726_c967cb3f69.jpg?v=0

Replace the highlighted line with this line, and you get this scene from the new camera.

Code Snippet
parentBox.InsertEntityGlobal(childBox);

http://farm2.static.flickr.com/1230/1403916398_5b5810940e.jpg?v=0

As you can see, the sky is no longer visible and the parent box looks distorted when viewed from the camera. If anyone has any suggestions for how to modify the camera to get around this problem, please let me know. Thanks!

[4794 byte] By [KathyChurch] at [2008-1-10]
# 1

Congratulations, you found a bug. Thanks for reporting it. We have some brain-dead code in our initialize methods that tries to initialize cameras but only looks at the first level of children of an entity. If you add a camera to a child of a child, the camera is not properly initialized. We'll fix the bug on our side and here's a work-around for you right now.

You will need to create a new camera class which inherits from the old one and overrides the Initialize method. After the camera has been initialized, you need to make an explicit call to SetProjectionParameters to set up the camera properly. Initialize takes a parameter that is an XNA type so you will also need to add Microsoft.Xna.Framework as a reference to your project. You can get instructions on how to do that here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1471018&SiteID=1

Add the following class definition:

Code Snippet

class FixedCameraEntity : CameraEntity
{
public FixedCameraEntity(int x, int y) : base(x, y) { }

public override void Initialize(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, PhysicsEngine physicsEngine)
{
base.Initialize(device, physicsEngine);
SetProjectionParameters(
ViewAngle,
((float)ViewSizeX / (float)ViewSizeY),
Near,
Far,
ViewSizeX,
ViewSizeY);
}
}

and don't forget to update your references to CameraEntity to now use FixedCameraEntity.

Also, I noticed when running your code that the joint between the parentbox and the childbox is not created properly because the Pose in the childbox is not initialized properly (the Quaternion orienation in the pose is (0,0,0,0)). You can fix this by explicitly setting the pose orientation explicitly like this:

Code Snippet

childBox.State.Pose.Orientation = new Quaternion(0, 0, 0, 1);

-Kyle

KyleJ-MSFT at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...

Microsoft Robotics Studio

Site Classified