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.

What I want to do is create my graphics to be independent of the game framework. So basically the graphics won't know anything until it is told where things are. so the thought was that every GameObject would hold its own transform like here, but then I would also want to calculate the camera, and say a directional light based on these as well.

My thought was to in an update method:

  1. receive a container of objects,
  2. step through them to get the needed data to be rendered (full transform matrix, and enums resulting in model to be rendered, and texture/material to be applied)

3.0 put that data into something like a stack. 3.1. when the player object is found calculate the position of the camera behind/above the player at a determined downward angle, and a directional light in front of the player at the same orientation.

  1. 4.in the render method pop the information off the stack to be rendered to the screen.
  2. 5.possibly using the frustum of the camera to ignore some objects (can be overlooked)

I have gotten steps 1, 3.0 and 4 completely working, step 2 I can get the enums out, but I still don't know how to apply the transform matrix to be usable (answers to above link would be greatly appreciated), and then 3.1 is a total mystery to me. as stated 5 would be nice, but can be overlooked if not possible (formatting edit requested)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You apply matrices in the vertex shader, you have to calculate it and pass it to the shader. You have the transform matrix, I'm assuming that's effectively your model to world matrix, maybe without scaling.

Then if you want to set up your camera, you'll need to have have camera translation and orientation in world space, it's a regular object, you can move it and rotate it as you like, this information is used to calculate the world to camera matrix, it's not anything hard if you understand matrix calculations. You apply this matrix after transforming from model to world space.

Now, you should have your vertices in camera space. Now you have to do perspective projection, this transforms vertices and effectively squeezes the back end of the view volume, you get a cube (an irregular cube, I don't know the English term, depending on how you set up your view volume), it's too complicated to explain the whole process here. Then you have to scale the view volume so it matches the homogeneous clip space, for DirectX it's [-1, 1] on the x and y axis and [0, 1] on the z axis IIRC. You don't have to know this, this whole transformation is a simple matrix, you just have to fill the appropriate fields correctly.

This homogeneous clip space gets transformed into NDC (it's a hardware operation, it divides x y and z of a vertex by w component, if you set up the projection matrix, this will achieve the actual projection and give you 3D space instead of 4D).

I'm saying all this to show you that calculating the camera is a non issue, you just set it up properly and calculate the world to camera matrix once per frame.

Also once you understand this transformation then frustum culling gets easy because the view volume is just an AABB in homogeneous clip space.

How you send this information to the renderer (as a stack or as a scene object) is up to you.

share|improve this answer
    
not sure I follow everything here. Is there anyway that I can see an example of these manipulations? –  gardian06 May 5 '12 at 21:47
    
@gardian06 if you do understand how matrix transformation works then perspective projection is explained in an accessible manner here: youtube.com/… it'll show you how to set up your camera, rest is the rendering pipeline, it's better explained in books, unless you don't understand specific parts –  dreta May 5 '12 at 22:51
    
alright that explained the perspective projection stuff pretty well. though I am still a little lost on the "You apply matrices in the vertex shader, you have to calculate it and pass it to the shader." could you maybe go to the linked question, and explain that process there, or give an example as I have not worked with shaders much –  gardian06 May 6 '12 at 3:11
add comment

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.