Difference of fields World & Projection

Jul 1, 2011 at 4:20 PM

Hello,

 

I'm a beginner with SLAR & Balder and am trying to adapt the samples provided by the SLAR TK to use my own object (instead of mesh from ASE files, pitcures, etc).

I started from the sample "SLARToolKitBalderSample" (The one wich displays a car, a tank, a teapot or a rounded cube), added a class MyBox inheriting from Balder.Objects.Geometries.Geometry and whose Prepare() method draws a cube on the viewport. I've replaced meshes with BlueBox (an instance of MyBox) and obtained such a code for applying projection to my box:

[...]
var trans = ToBalderMatrix(detectedResult.Transformation); ApplyFinalTransformation(trans);
 
[...]

      private void ApplyFinalTransformation(Matrix baseTransformation3D)
      {
          // Transform the mesh and change coordinate system
          // Apply the final transformation matrix to the TextBox

          // Transform the mesh and change coordinate system
          var centerImageAtOrigin = Matrix.CreateTranslation(Convert.ToInt32(-40 * 0.5), Convert.ToInt32(-40 * 0.5), 0);
          var trans = centerImageAtOrigin * baseTransformation3D;
          BlueBox.World = trans;
      }


First I don't understand why in some samples, to apply the final transformation we update te field Object.Projection (for the TextBox and for the Sun/Moon sample e.g.) and in some others we update the field Object.World.
Depending of our choice, the result is not identical : With the code above (updating Object.World) my box doesn't keep aligned with the pattern when I take away the pattern from the center of the image (here is an illustation to what I'm meaning ; it occurs whith the car/tank/cube/teapot sample too). While by udpating the Object.Projection field, objects kepp aligned with the pattern (e.g. with the SLARToolKitSample Puzzle/Bear and TextBox).

Secondly, I would like my box to stay aligned with the pattern, I try to update the field BlueBox.Projection instead of BlueBox.World. Unfortunately I guess that this field is not read to display my own object because the box stays motionless. What can I do?


Thx by advance :)

Coordinator
Jul 2, 2011 at 5:37 PM

The Projection property is from Silverlight.  The World property comes from the Balder project. You have to use the World property to apply the transformation to the object.

Just use the Balder sample as it is and only replace the model.

 

- Rene Schulte

Jul 3, 2011 at 7:36 PM

OK thx but by using the World property my object takes a good orientation but does not always stay on the pattern. Do you see what I'm trying to mean?

http://cjoint.com/?0Gbsn5SV9pu : On this illustration the blue box should always hide the pattern. But actually when the pattern is far from the center of the image, the box leaves it.

In the provided samples the cases where the object stays exactly on the pattern (Sun/Moon and textbox) are when they use the Projection property. I don't know how to do that with the World property to do that.

Jul 4, 2011 at 9:36 AM

In addition to the precedent issue, I wonder how the LoadFromResource() function use its 4th parameter to reconstruct the position and orientation in space.

And particularly what is the relation between the Viewport grid unit (in pixels?) and the given size of the pattern in millimeters (80.0 mm by default).

Actually I would like to display a 80x80x80 mm cube onto a 80x80 mm pattern.

Here the cube should hide the pattern entirely. But if I draw the box with those coordinates the drawn bow is much bigger that the 80x80mm pattern in reality:

 

                var frontUpperLeft = new Vertex(0, 0, 80);
                var frontUpperRight = new Vertex(80, 0, 80);
                var frontLowerLeft = new Vertex(0, 0, 0);
                var frontLowerRight = new Vertex(80, 0, 0);
etc ...


 

I need to draw objects whose position and dimensions are quite precise on the scene. That is why I am asking those questions :)

Thank you