# is projection worth making seperate module on it

This topic is 1791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i got separate camera module (file) and it is very much ok,

but then i got also a projection code 3d->2d projection

which uses the camera mentioned

Is it good to make this projection separate module?

'Physically' both camera and 'projector; are well separated

'physical' entities soit seem to me that it is worth it?

How are the personal opinions

##### Share on other sites

I crammed them together.  At my engine level its plain C, so it looks like this:

gx_camera_set(&player.camera);  //everything after this call will be drawn from the POV of the player

//player is an entity:

typedef struct entity_s{
gx_sector_t* current_sector;  //pointer to current sector player is in
gx_camera_t camera;
//... other stuff
} entity_t;

//The camera contains position, orientation info:

typedef struct gx_camera_s
{
vec3   position;
mat33  orientation;
float  view_angle;
} gx_camera_t;

gx_camera_set will set up the modelview matrix and projection matrix so things are drawn from the player's point of view, with the view frustum angle approximating the view_angle value.  If the player zooms in with a scope, view_angle shrinks.  View angle is used for first-pass culling, etc.

Non-player entities (enemies) ALSO have cameras for two reasons:  I can view the world from their point of view (its cool for debugging, you can watch the entity follow you, and see when it mistakenly 'sees' or 'doesnt see' you).  My code to see if something is in my field of view (and thus determines if I should draw it; 'it' being the other entities) is the same code the enemies use to see if something is in their field of view (and thus determines they should chase it; 'it' being the player of course), is the same code.

Edited by carangil

##### Share on other sites

I'd say projection is just a property of the camera. It is somewhat similar to the lens setting on a real world camera.

It doesn't really have anything to do with a "projector" (as in a device that shows images by projection).

So it would make sense to keep them together.

For a 3D camera, you usually keep this information in a projection matrix, which you set up once. (or possibly more times if you change things like fov dynamically)

Edited by Olof Hedman

##### Share on other sites

I'd say projection is just a property of the camera. It is somewhat similar to the lens setting on a real world camera.

It doesn't really have anything to do with a "projector" (as in a device that shows images by projection).

So it would make sense to keep them together.

For a 3D camera, you usually keep this information in a projection matrix, which you set up once. (or possibly more times if you change things like fov dynamically)

I never used projection matrix, i do only 'proportional division',

does the projection matrix work faster ? how would it work, it takes

3d vector multiplies by matrix and got 2d point output as an result?

##### Share on other sites

I'm assuming you are writing a software renderer, if so, it's not necessarily  faster, but it can be more convenient, and is more flexible.

The idea is you can multiply it together with the view matrix that define the camera position, and then for each model, with the model matrix that define an objects position, and then process all vertexes for that object with one matrix multiplication per vertex.

You still have to do a divide after though, but if you use hardware, it will do it for you, and the hardware is built around the idea you use matrix multiplication for all your transformation needs.

Here is one brief article, a quick google on the concepts described there should give you all the details you need: http://www.codinglabs.net/article_world_view_projection_matrix.aspx

##### Share on other sites

I'm assuming you are writing a software renderer, if so, it's not necessarily  faster, but it can be more convenient, and is more flexible.

The idea is you can multiply it together with the view matrix that define the camera position, and then for each model, with the model matrix that define an objects position, and then process all vertexes for that object with one matrix multiplication per vertex.

You still have to do a divide after though, but if you use hardware, it will do it for you, and the hardware is built around the idea you use matrix multiplication for all your transformation needs.

Here is one brief article, a quick google on the concepts described there should give you all the details you need: http://www.codinglabs.net/article_world_view_projection_matrix.aspx

ye, im writing it (I wrote but simple one) then i get to consciouss that this projection & perspective things are still not quite clear to me, tnx for info

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634111
• Total Posts
3015573
×