Orthographic projection

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Orthographic projection

Post by saigumi »

I finally figured out the term I was looking for.

I would love to be able to create an Orthographic view. Unfortunately, every 3d tutorial out there says "use D3D_OrthoLH()" or "use glOrtho()"

Anyone know offhand how to generate an orthographic matrix without making a direct call to the D3D or gl API?
Crud, how do I do this again?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Try matrix4::buildProjectionMatrixOrthoLH :)

http://irrlicht.sourceforge.net/docu/cl ... 4.html#a32
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

A-ha!

I kept searching the documentation for this, but merely putting "ortho" into the windows help search bar found nothing.

"*ortho*" worked.

Thanks Niko.
Crud, how do I do this again?
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Ok, I've pretty much worked through everything, got a basic understanding of ortho rendering but I'm stumbling on something that I can't figure out.

I'm not exactly sure why it's not working but let me give you an example. (I'll try to rip out the source and post an example if I can't get it figured out tonight. Heck, I'll probably just pull the source anyhow and post it as another Howto)

Say I have a map of 9 blocks with 5 being the center at 0,0,0 (x,y,z)

123
456
789

I move the camera to -1,1,-1. This should mean that I now see.

__3__
_2_6_
1_5_9
_4_8_
__7__


Which I do... but the blocks on the lower Z are rendered behind those with a higher Z... which is backwards because the lower Z is supposed to be closer. (Distance is a relative term in ortho since it's all flat.)

In the end, I see this:

(Beware, character drawing ahead worse than Niko's from the source on TestSceneNode)
..__
./_/| 3 (Z = 1)
|_|/| 5 (Z = 0)
|_|/| 7 (Z = -1)
|_|/

When I expected to see this

..__
./_/| 3 (Z = 1)
./_/| 5 (Z = 0)
./_/| 7 (Z = -1)
|_|/

Is then something I need to do to change the sort order?
Crud, how do I do this again?
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

--- moved this message to where it is supposed to be so that it will make senese ---

Fixed my problem... just by trying out a stupid idea, and I'm not wholey sure it's good.

It seems that this line was wrong.

Code: Select all

// buildProjectionMatrixOrthoLH(width, height, near, far)
MyMatrix.buildProjectionMatrixOrthoLH(16.0f,12.0f,-3.5f,3.5f);
Looks right to you? Me too. It seems that I had the near and far backwards.

Code: Select all

// buildProjectionMatrixOrthoLH(width, height, near, far)
MyMatrix.buildProjectionMatrixOrthoLH(16.0f,12.0f,3.5f,-3.5f);
And now that I got that figured out, I've started heavilly on the tutorial.

The code and one of Pharoseer's lovely creations (a cube with a dummy texture) is here.

http://www.saigumi.net/orthogonal.zip
Crud, how do I do this again?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Cool. I have no experience with this. But I think this is a good place for the next one asking how to do 2d or isometric renderings with the engine.
Suliman

Post by Suliman »

This seemes very useful indeed.

Could you put that example up again saigumi? I need some working example to understand what its all about.
devil20
Posts: 14
Joined: Wed Jan 19, 2005 2:28 pm
Location: UK

also i need !!

Post by devil20 »

Hey
Your link of tutorial code is broken !!!!

http://www.saigumi.net/orthogonal.zip

can u check it ? i ready to download ... Or please can u send me to alexdowson@hotmail.com ???


devil20
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Well, the tutorial is completely gone due to some bad luck.

I put the file back though, in the downloads directory.

http://www.saigumi.net/downloads/orthogonal.zip
Crud, how do I do this again?
devil20
Posts: 14
Joined: Wed Jan 19, 2005 2:28 pm
Location: UK

Now working

Post by devil20 »

Now working ...:)

Thanx for upload. :)

devil20
Suliman

Post by Suliman »

It has very short drawing distance so i try to change it with

camera->setFarValue

but that completely reinstates the perspective-thing. And then its no longer orthogonal...
Guest

Post by Guest »

Code: Select all

// buildProjectionMatrixOrthoLH(width, height, near, far) 
MyMatrix.buildProjectionMatrixOrthoLH(16.0f,12.0f,3.5f,-3.5f); 
Just change the 3.5f and the -3.5f.
hybrid

Re: Now working

Post by hybrid »

devil20 wrote:Now working ...:)
How that? Should be EDT_DIRECTX8 not DT_DIRECTX8 ???
But then you're right :wink:
roninmagus
Posts: 91
Joined: Fri Oct 31, 2003 5:03 am

Post by roninmagus »

Here is some code I wrote a while back that some people may find useful. This is code modified from the second tutorial of dusty engine, available at http://daveandrews.org/dustyengine/tuto ... orial2.php.

Code: Select all

ICameraSceneNode * SetupCamera(IrrlichtDevice * irrDevice)
{
	ICameraSceneNode * camera = irrDevice->getSceneManager()->addCameraSceneNode();
	matrix4 orthoMatrix;
	orthoMatrix.buildProjectionMatrixOrthoLH(16.0f, 16.0f, 2.0f, -2.0f);
	camera->setProjectionMatrix(orthoMatrix);

    return camera;
}
Of course, I couldn't write that code until reading saigumi's orthagonal tutorial at http://www.saigumi.net/archives/000067.html Kudos!
daveandrews.org - A Christian Programmer's Weblog | Dusty Engine - A Task Engine for Irrlicht
Muhaha
Posts: 17
Joined: Wed Feb 13, 2008 10:07 am

Post by Muhaha »

saigumi wrote:Well, the tutorial is completely gone due to some bad luck.

I put the file back though, in the downloads directory.

http://www.saigumi.net/downloads/orthogonal.zip
someone can send me this tutorial ?

thank you.
Post Reply