4
$\begingroup$

I want to ray trace a triangular mesh that I load from a file. The vertices' coordinates are expressed in the reference frame associated with the object (i.e the mesh) and I don't know the object-to-world matrix. Is there a way to calculate this matrix given these coordinates? If no, how can I ensure that the mesh's triangles are transformed to the world's reference frame?

$\endgroup$

2 Answers 2

4
$\begingroup$

No! If you dont have this info and must have a extra frame, just assume the reference frame is a identity matrix*. The point of the extra reference frame is just to be able to move the object but if you have no info about how the object should relate to other objects it does not really matter operator can move it where they want. Everything is relative, if theres no relation then no problems.

* choosing identity is like choosing a arbitrary constant to be 1, its numerically easy to work with.

$\endgroup$
2
  • $\begingroup$ Using the identity matrix is equivalent to placing the object at the origin, with no scaling, and no rotation. $\endgroup$
    – RichieSams
    Jan 28, 2016 at 19:29
  • $\begingroup$ @RichieSams yes, same as putting object to world coordinates (or other parent), except theres a matrix in between to manipulate. $\endgroup$
    – joojaa
    Jan 28, 2016 at 19:46
2
$\begingroup$

The Object-To-World matrix is often called "model-matrix".

This martix tells us how the object relates to some "World". This world is relative and arbitrary but really convenient because we can place all our objects and even the camera in it and the math works out pretty well.

The short answer is, that you imagine that the model is defined in the origin of the world, so that the center of gravity of the object lies exactly in the $(0.0, 0.0, 0.0)$ position of the world.

Now if you want to place multiple objects in the same scene, you have to give them a position, and it is really convenient to give all objects a position relative to this world-origin. So you just create a matrix for each object that tells you how you move the object in relation to the world-origin.

For example translating an object is $\begin{bmatrix} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 1 & z \\ 0 & 0 & 0 & 1 \end{bmatrix} $ then your object will have the world-relative position of $(x, y, z)$ (I will omit the useage of homogeneous coordinates which would be better suited for another question).

In a similar fashion you can use translation, scaling and rotation (take care of what order you apply these transformations)

Things get a bit complicated if you want to do camera-space computations and projections and stuff like that, but in the simplest version you can just build your model-matrix this way.

Multiplying each point of your model with this model-matrix gives you the position of the point in world-space (meaning relative to the origin of the world!) and for meshes this moves the whole model just as you would expect.

$\endgroup$
3
  • $\begingroup$ Is it correct to think of this model-matrix as a model-to-world matrix? in case I want to transform a point to the coordinate system of the model, then will I have to use the inverse of the model-matrix? $\endgroup$
    – BRabbit27
    Jun 2, 2016 at 5:24
  • $\begingroup$ Regarding the camera-matrix (built with cam position, lookat point and up vector), can I call it a camera-to-world matrix? Then, if I want to go from world to camera space, will I have to use the inverse of that camera-matrix? $\endgroup$
    – BRabbit27
    Jun 2, 2016 at 5:27
  • 1
    $\begingroup$ The model-matrix is indeed a model-to-world matrix. If you can call the camera-matrix or often view-matrix a "camera-to-world" or "world-to-camera" matrix depends on how you build it i think. I aways use a approach of "world-to-camera" in which the matrix is composed with the coordinate system and the negative position of the camera. Then multiplying by this takes a world coordinate into camera/view space. opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices explains this in a much more detailed fashion and in the way I use the terms and matrices. $\endgroup$
    – Dragonseel
    Jun 2, 2016 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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