user3252833
user3252833

Reputation: 129

2 Mesh.Box among each other

I use directx with C# (MDX). And my Task is it so put two Boxes (created with Mesh.Box) among each other.

The top box has:

width: 200 height: 10 depth: 1

The bottom box has:

width: 10 height: 100 depth: 1

Both together should look like

-----------
          -
          -
          -
          -

Now I have the Problem, that i don't know how to calcultate the right Translation for both:

Top Box:

d3dDevice.Transform.World = Matrix.Translation(0, 20, 30.0f);

Bottom Box:

d3dDevice.Transform.World = Matrix.Translation(195, -40, 30.0f);

Now the bottom Box isn't direct among the top box.

I think that I must calculate Z but I don't know how i do this. Can someone help me?

Upvotes: 0

Views: 56

Answers (1)

Nico Schertler
Nico Schertler

Reputation: 32597

The created boxes are centered at the origin. So the only thing you have to do is adjusting the x and y-coordinate. The top box has to be bottom height / 2 + top height / 2 units higher than the bottom one and top width / 2 - bottom width / 2 units to the left. So:

//top box
d3dDevice.Transform.World = Matrix.Translation(-195, 55, 0);

//bottom box
d3dDevice.Transform.World = Matrix.Identity();

Or

//top box
d3dDevice.Transform.World = Matrix.Translation(0, 55, 0);

//bottom box
d3dDevice.Transform.World = Matrix.Translation(195, 0, 0);

Apart from that you can specify any other transformation. As long as you apply it to both boxes. E.g. move the boxes around:

//top box
d3dDevice.Transform.World = Matrix.Translation(30, 75, 30);

//bottom box
d3dDevice.Transform.World = Matrix.Translation(225, 20, 30);

Upvotes: 1

Related Questions