Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a Triangle class and a list of triangles representing my 3D model shape.

When I update the position, the rotation or the scale of my model, I also want my triangles list to be updated.

I already made the function to update triangle position, but I can't make it for rotation/scale...

private void UpdateModelTrianglesPos(Vector3 oldPos, Vector3 newPos)
{
    Vector3 diff = newPos - oldPos;
    for (int i = 0; i < _trianglesPositions.Count; i++)
        _trianglesPositions[i].UpdatePosition(diff);
}

Thank you for your help!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This is a bad way to go about it. Every time you want to move your model AT ALL you have to change every triangle.

You should have one transform per mesh. I assume you have a model class, so what you'll want to do is give each model class either 3 vectors for scale, rotation, and translation or a single matrix. When you want to move the model you simply have to change the vectors or matrix accordingly.

Now, right before you draw you should upload your transform to your vertex shader. Now you can use it as needed uniformly across all your vertices.

This is a pretty standard way of dealing with this. A vertex should only describe it's local coordinates. That is, its position relative to other vertices in the model. You then construct your model matrix per model object, and your view matrix per viewport.

Your scene should follow this structure:

Per Vertex               Per Model               Per Viewport    Everything is now pixels
local coordindates -> model coordinates -> model view coordinates -> screen coordinates.

Hope this helps. Just read up on your 3D theory and you'll get it in no time!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.