Skip to main content
GameDev.net gamedev.net
🔒 Locked

What does this code do?

Started by Mulligan Nov 24, 2003 at 10:21 PM 6 replies 700+ views
Original Post
Mulligan
Mulligan
I was over at....flipcode...and saw this code: http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-glToScreen&forum=cotd&id=-1 The author really fails to explain what it does, can anyone explain it in english?
Timbatron
Timbatron
Yea he does, it projects from object space to screen space with the current matrices.

[edited by - timbatron on November 24, 2003 11:34:12 PM]
My Page : http://acidbase.computed.net
Mulligan
Mulligan
"in english"
Mage2k
Mage2k
Well, without reading the code your talking about but going on what Timbatron said, I can tell you that to project something from object space (or world space or model/view space in directx and opengl terms) is to that object''s 3d coordinates and map then onto 2d coordinates for drawing on the screen (screen space).

peace and (trance) out

Mage
---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage
Rob Loach
Rob Loach
If you don't know what it means, then I recommend you do some research and find out.

"In English", like Timbatron said, it projects from object space to screen space with the current matrices.

[edited by - Rob Loach on November 24, 2003 12:53:23 AM]
Rob Loach [Website] [Projects] [
RonHiler
RonHiler
Here, I'll give it a try. I'm not going to look at the COTD, but I understand what he's doing from your description

The reason you are getting such short answers is that, to 3D programmers, "it projects from object space to screen space with the current matrices" *is* plain english This is a very basic concept in 3D programming, it's pretty much the first thing your learn.

But if you are not a 3D programmer, it wouldn't make any sense. So I'll explain it a bit.

When a modeller makes a 3D model, they generally center the model somewhere near itself, often at it's center of mass, or perhaps just underneath the model (especially if it's something that is meant to stand on a floor). Like a chair for instance, I'd put the origin under the chair at floor level, centered between the legs. This is called model space, and all the vertices of the model are in relation to the model's origin. With me so far?

Okay, but now you want to put this model into your world. Worlds also have an origin. If you just dropped all your models into the world without transforming them, the origin of the model would be the same as the world origin. All your models would be sitting in the same place! That's obviously no good, so you use a matrix to place them, namely the World matrix. What the world matrix does is to tranlate and rotate your model's vertices to a particular place in your world. So, for instance, I could model a tree, then render the model using 50 slightly different world matrices, and suddenly I have a forest! We've moved from model space into world space using this matrix. All we've done is change the referece point of the model's vertices from their own origin to the world's origin. So far so good?

But wait, there's more! We have a world populated by models, but we have no frame of reference. What we need is a "camera", which is to say, a point from which the player looks at the world. To get this camera, we create a new matrix, called the View matrix. This matrix puts our player into the world itself. Now, I'll let you in on a 3D programmer's secret. The camera never moves. It sits at the world origin, and the world moves around it! This is actually a lot easier mathmatically to handle that actually moving the camera, believe it or not But you can think of the camera as moving in the world if you like, it amounts to the same thing. Using this second matrix, we have moved from world space into view space, and now every vertex in the models are relative to the camera position.

So, now we have a world, and we have the camera in the world, but we're not done yet. The world and the camera are all in 3D, but our viewscreen is a 2D thing. In order to convert our 3D world into something a typical monitor can handle, we use a projection matrix. This matrix allows us to "project" what the camera is seeing onto our viewscreen while still providing a sense of depth to the scene. This is screen space.

So, in conclusion, that's what that means, projecting from "object space to screen space with the current matrices" simply means the author has taken a set of three matrices (World, View, and Projection) and applied them to a model such that the vertices of the model, which started in model space, are now related to screen space.

Note that I dislike the term "object space" because it's not well defined (AFAIK). I've seen it defined as either model space or world space, depending on who you read, so I'm not sure which one is being referred to here. I think *usually* it refers to model space. Perhaps there is a formal definition of which I'm unaware

Hope that helps.

[edited by - RonHiler on November 25, 2003 1:51:18 AM]
Creation is an act of sheer will
Greatwolf
Greatwolf
Thank you RonHiler, now that''s an explanation! I haven''t gotten into 3d programming yet so the explaination has given me a quick feel for what 3d programming is about.

Thanks





--{You fight like a dairy farmer!}
--{You fight like a dairy farmer!}
Mulligan
Mulligan
Well thank you RonHiler! Its a LOT more helpful to answer questions than it is to say "read it again". Without getting all fruity, its nice to have people like Ron around from keeping this messageboard from becoming the crap its turning into.

[edited by - Mulligan on November 25, 2003 3:33:33 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.