General 3D object translation question

Nov 13, 2009 at 2:54 PM

I can create meshes programmatically at the origin and in general, I can translate them anywhere,, if the translation is simple.

I have a need to create a random planar object (could be rectangle, square, trapezoid, rhomboid...etc).  Is there a way to translate the corners to a particular position?  By this I mean, can I create a plane and then specify the location of say, two of the corner vertices, and then translate the object to that location?

I need to build a fairly smooth, sectional ramp between multiple levels that are randomly spaced in height.  Any thooughts or assistance would be welcome.

Nov 14, 2009 at 9:50 AM

If I understand you correctly, you are talking about what is known as the ability to define a Pivot point or the point of origin for transformation.

There is no Pivot support at the moment. The only way I can come up with as a possibility to get around this at the moment would be to apply the pivot point manually before it is rendered to the actual vertices. I'll add an issue for it at GitHub.

Nov 16, 2009 at 6:26 PM

I am not sure I understand exactly what a pivot point is.  What I want to accomplish is to relocate an object, in this case a dynamically created rectangular plane, from the origin to a specific point where the corner vertices of the object match the vertices of other objects.  If PivotPoint support is required to do this, then I will think about the vector transforms necessary to do this in place when I define my object, using the positions of the vertices I need to connect to.  Do you think it will work if I do the vector math during the creation of these objects, and do you think it will be fast enough? 

Nov 16, 2009 at 6:33 PM

The fastest would be to do all these transformations when generating the objects and dynamically create the model as you want it to look like - that will produce the best performance. You can achieve this by creating the necessary Matrices as you generate and apply these to the Vertices you want.


Nov 16, 2009 at 8:30 PM

I understand that I should do it this way  What I am still grasping at is the mechanics of doing this...Once I generate a set of vertices and faces, how to I translate it to a position where the corners of my rectangle match existing points in my model?

Nov 17, 2009 at 7:39 AM

You could use the static helper methods on Matrix to create the matrices you need:

Matrix.CreateTranslation(new Vector(xpos,ypos,zpos));


then before creating the Vertex, you create it as a Vector and multiply it with the Matrix:


var matrix = Matrix.CreateTranslation(-50,0,0);
var vector = new Vector(0,0,0);
var resultVector = vector * matrix;
var vertex = new Vertex(vector.X, vector.Y, vector.Z);


Nov 17, 2009 at 2:41 PM

Excellent....thanks.  That will work for my needs.