World position of vertex?

About Monkey 2 Forums Monkey 2 Programming Help World position of vertex?

This topic contains 4 replies, has 2 voices, and was last updated by  DruggedBunny 1 month, 1 week ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14328

    DruggedBunny
    Participant

    How do I get hold of the world position of a mesh’s vertex? I’m trying to visualise a terrain’s vertices, and have got my mesh vertices easily enough, but it’s just the ‘raw’ mesh vertices rather than their current position in space…

    See DrawVertices:

    [/crayon]
    #14330

    Mark Sibly
    Keymaster

    Use something like entity.Matrix * vertex.position, eg:

    The matrix multiplication transforms the Vec3f position from one coord space (ie: local space) to another (ie: world space).

    To get from world space to local space instead, use the inverse matrix, eg: -entity.Matrix * worldPos.

    #14341

    DruggedBunny
    Participant

    Thanks, Mark, that looks to have done it… handy to know it was that simple!

    #14342

    Mark Sibly
    Keymaster

    The other usefull thing to know here is how multiplying matrices has the effect of ‘chaining’ a sequence of transforms together.

    So say you’ve got 2 entities, and a point in local space of one of the entities, and you want to transform it into the local space of the other entity, you can do something like -entity2.Matrix * entity1.Matrix * point.¬† This will transform a point from entity2’s local space to entity1’s local space. Note that matrix multiplication is not commutative (eg: matrix1*matrix2 is not the same as matrix2*matrix1) although it is associative (eg: (matrix1*matrix2)*matrix3 is the same as matrix1*(matrix2*matrix3)) and should generally be read ‘right to left’ (eg: the above first transforms point by entity1.Matrix and then by -entity2.Matrix). So by precalculating matrices like this, you can actually store a complex sequence of transforms in a singe matrix. This is what those weird sounding matrices like ‘ModelViewProjectionMatrix’ are actually doing, transforming from model space to view space to ‘clip’ space (another topic!)…

    And that’s it – that’s most of what I know about 3d!

    #14346

    DruggedBunny
    Participant

    Cool, thanks, have saved that for reference, will try grasp it, or as much as I need when I need it!

    I have stumbled across ModelViewProjectionMatrix and the like in GLSL fragment shaders, something I’ll be dabbling in again soon, and I realised earlier that this vertex drawing is probably a good candidate for shader-ising anyway.

    Got my terrain vertex drawing working for now, slow as heck (obviously), but this might actually help me narrow it down within a given range and speed up slightly.

    At least I can see where the vertices are in relation to my texture, which is what I was after!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.