Projection Matrix : Ooooh

BlitzMax Forums/BlitzMax Programming/Projection Matrix : Ooooh

TartanTangerine (was Indiepath)(Posted 2005) [#1]
Remember the old days with Blitz3d when you could just stick stuff in front of the camera, change the resolution and everything remained in the same position on screen? NO? oh well.

Here's how you do it in Bmax (and dont do it).

1) Scale all the image sizes and positions so that objects always look the same at each resolutions (YUK).
2) Change the projection Matrix so that it don't matter what resolution you run at, just decide what resolution to base everything off of and be done with it (YEAH).

How:-
' **** THE ACTUAL RESOLUTION OF THE SCREEN
Local ScreenWidth = 1024
Local ScreenHeight = 768

Graphics ScreenWidth,ScreenHeight,0

' **** THE BASE RESOLUTION THAT WE WILL USE TO PLACE ALL OBJECTS
Local Proj_width = 800
Local Proj_height = 600
Local matrix#[],depth=2

matrix=[..
2.0/Proj_width,0.0,0.0,0.0,..
0.0,-2.0/Proj_height,0.0,0.0,..
0.0,0.0,2.0/depth,0.0,..
-1-(1.0/Proj_width),1+(1.0/Proj_height),1.0,1.0]

primarydevice.Device.SetTransform(D3DTS_PROJECTION,matrix)


Example code:
DrawRect 790,0,10,10

Now change the actual screen resolution and the square will remain in the top right.


TartanTangerine (was Indiepath)(Posted 2005) [#2]
Now will someone help with Vertex Buffers?


Space_guy(Posted 2005) [#3]
it doesnt work for me. nothing gets drawn when i call the line "primarydevice.Device.SetTransform(D3DTS_PROJECTION,matrix)"

any clue ?


TartanTangerine (was Indiepath)(Posted 2005) [#4]
Ooops, Copy and Paste error, try again.


Robert Cummings(Posted 2005) [#5]
Can we get this for openGL?

Actually what I've always wanted is camera-level scale, position and rotation. This means you can make all sorts of funky effects without the irritating and (frankly unecessary) task of doing it to all 'objects'.


TartanTangerine (was Indiepath)(Posted 2005) [#6]
I'm no expert BUT here you go.

Local Proj_width = 800
Local Proj_height = 600

glMatrixMode GL_PROJECTION
glLoadIdentity
glOrtho 0,Proj_width,Proj_height,0,-1,1
glMatrixMode GL_MODELVIEW


vertex Buffers anyone?


Rimmsy(Posted 2005) [#7]
Dude, I wish I could help. You're a real hero when it comes to free code. Have you tried emailing mark about it?


Shambler(Posted 2005) [#8]
Have you managed to locate the DirectX7 docs anywhere on the net..searched for hours but can't find them -.-


TartanTangerine (was Indiepath)(Posted 2005) [#9]
Na, I've not emailed Mark. I'll try that soon.

I can't find any good reference documentation either, I've a few examples, enough to teach my how to use them. Problem is that I'm no expert on C++, it's like alien to me, and converting C++ properly to BMax is beyond my current capabilities. It's all this stuff with pointers and LPVOID*, it's like DirectX wants to give me an address to a buffer but BMAX won't let that happen since it wants me to have already defined a buffer.

There must be someone here who know this stuff?


Braincell(Posted 2005) [#10]
Tom (Scouse) sounds like someone who should exactly know this stuff. He's on IRC most of the time as well. He does lots of c++ but claimed he doesnt quite understand it all. Ask him.


TartanTangerine (was Indiepath)(Posted 2005) [#11]
I'll see if I can bend his ear tomorrow. Does he know Bmax?


Tom(Posted 2005) [#12]
A little yeah :)

I'll go ahead and compile you modded DX stuff and have a go at the vertex buffer problem, catch you in the other thread later.


xlsior(Posted 2005) [#13]
This sounds like it could be -very- useful, an easy way of implementing multiple resolutions in a game...

(Although you wouldn't 'gain' anything when scaling down to a lower resolution since internally you're still doing the work for a higher resolution I suppose)


TartanTangerine (was Indiepath)(Posted 2005) [#14]
The gain is the fact that you do not have to scale and calculate the position of every image based on the current screen resolution. Think of all that maths you are saving.


xlsior(Posted 2005) [#15]
Good point, I'll definitely be playing around with this one!


Ferminho(Posted 2005) [#16]
Works great, at least in opengl mode! (I'm currently having problems with B+' directx driver)
Thanks a lot...

...only issue to take into account real resolution is when using grabimage/pixmap (image it's grabbed at the real res but when drawing it has to be resized to fit the screen again) and of course setviewport. Made minor changes in my code and everything is working OK at every resolution

Thanks again! your codes are always of great help


Ferminho(Posted 2005) [#17]
Confirmation: works great in DX mode too


Robert Cummings(Posted 2005) [#18]
So will this be added to bmax?

Mark should add it because if you were going to do this manually, you would need to change all your physics timing, playability, movement - EVERYTHING-

And thats quite a pain in the rectum as opposed to the simple and elegent solution above.


TartanTangerine (was Indiepath)(Posted 2005) [#19]
I don't think Mark needs to add this, all it's doing is updating the Projection Matrix which has more to do with DirectX and OpenGl than BMax.

Maybe one day I'll wrap all these functions into a funky module and fleece you all for a few quid.