December 04, 2020, 11:17:01 AM

Author Topic: [bmx] Projection Matrix by _Skully [ 1+ years ago ]  (Read 467 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Projection Matrix by _Skully [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Projection Matrix
Author : _Skully
Posted : 1+ years ago

Description : Projection Matrix - Scaling your game on the fly
"Yan to GfK to me to here :)


Code :
Code: BlitzMax
  1. [code]
  2. Type TVirtualGraphics
  3.         Global virtualWidth, virtualHeight
  4.         Global xRatio!, yRatio!
  5.        
  6.         Function Set(width=640, height=480, scale#=1)
  7.                 TVirtualGraphics.virtualWidth = width
  8.                 TVirtualGraphics.virtualHeight = height
  9.                 TVirtualGraphics.xRatio! = width / Double(GraphicsWidth())
  10.                 TVirtualGraphics.yRatio! = height / Double(GraphicsHeight())
  11.                
  12.         ?Win32
  13.                 Local dxVer:Byte
  14.                 Local D3D7Driver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)
  15.                 Local D3D9Driver:TD3D9Max2DDriver = TD3D9Max2DDriver(_max2dDriver)
  16.  
  17.                 If TD3D7Max2DDriver(_max2dDriver) <> Null
  18.                         dxVer = 7
  19.                 EndIf
  20.                 If TD3D9Max2DDriver(_max2dDriver) <> Null
  21.                         dxVer = 9
  22.                 EndIf
  23.  
  24.                 If dxVer <> 0 'dx driver was set, otherwise its GL
  25.                         Local matrix#[] = [2.0 / (width / scale#), 0.0, 0.0, 0.0,..
  26.                                                                                                         0.0, -2.0 / (height / scale#), 0.0, 0.0,..
  27.                                                                                                         0.0, 0.0, 1.0, 0.0,..
  28.                                                                                                         -1 - (1.0 / width), 1 + (1.0 / height), 1.0, 1.0] ',scale#]
  29.                        
  30.                         Select dxVer
  31.                                 Case 7
  32.                                         D3D7Driver.device.SetTransform(D3DTS_PROJECTION, matrix)
  33.                                 Case 9
  34.                                         D3D9Driver._D3DDevice9.SetTransform(D3DTS_PROJECTION, matrix)
  35.                         End Select
  36.                 Else
  37.         ?
  38.                 glMatrixMode(GL_PROJECTION)
  39.                 glLoadIdentity()
  40.                 glOrtho(0, width / scale:Float, height / scale:Float, 0, - 1, 1)
  41.                 glMatrixMode(GL_MODELVIEW)
  42.                 glLoadIdentity()
  43.         ?Win32
  44.                 EndIf
  45.         ?
  46.         End Function
  47.        
  48.         Function MouseX()
  49.                 Return (BRL.PolledInput.MouseX() * TVirtualGraphics.xRatio!)
  50.         End Function
  51.        
  52.         Function MouseY()
  53.                 Return (BRL.PolledInput.MouseY() * TVirtualGraphics.yRatio!)
  54.         End Function
  55. End Type
  56.  
[/code]

Comments :


QuickSilva(Posted 1+ years ago)

 Any chance of a usage example?Does this method cause the same sort of performance hit that simply scaling the display up using the SetScale command does? For example, if I set my game to 2 times the scale my framerate drops by half using SetScale. Would this method do the same? [Edit - OK it does.]Also, I`m getting a driver not found for the DX9 one. I assume that you have to find this yourself? Maybe this should be mentioned for new users?Other than that what are the main reasons for using this method over a simple SetScale on all game objects?Jason.


GW(Posted 1+ years ago)

 <a href="http://code.google.com/p/max2ddx9/" target="_blank">http://code.google.com/p/max2ddx9/[/url]


_Skully(Posted 1+ years ago)

 Usage is simple enough
Code: [Select]
T:TVirtualGraphics=new TVirtualGraphics
T.Set(800,600)
done...


Nigel Brown(Posted 1+ years ago)

 Compiler Error Identifier 'TD3DpMax2DDriver' not foundJust downloaded and installed the above max2ddx9 link, yet get this error?


_Skully(Posted 1+ years ago)

 Did you compile it?You could always comment out the DX9 stuff to test it if thats what your looking to do.


GfK(Posted 1+ years ago)

 <div class="quote"> Usage is simple enoughT:TVirtualGraphics=new TVirtualGraphicsT.Set(800,600) </div>Its not even THAT complex - you don't need to create a tVirtualGraphics object as it uses Global/Function rather than Field/Method:
Code: [Select]
Graphics 1024,768 'or any user-defined res
tVirtualGraphics.Set(800,600)



therevills(Posted 1+ years ago)

 Heres a quick example (without DX9):
Code: [Select]
Graphics 1024,768,0 'or any user-defined res
tVirtualGraphics.Set(800,600)
AutoMidHandle 1
Global BMX01IMG:TImage = LoadImage("C:BlitzMaxsamplesirdiemiscfilmclipmediaB-Max.png",FILTEREDIMAGE|DYNAMICIMAGE)

While Not AppTerminate()
Cls
DrawLine 0,0,TVirtualGraphics.virtualWidth,TVirtualGraphics.virtualHeight
DrawImage BMX01IMG,TVirtualGraphics.virtualWidth/2,TVirtualGraphics.virtualHeight/2
DrawText "Virtual Width: "+TVirtualGraphics.virtualWidth,10,10
DrawText "Virtual Width: "+TVirtualGraphics.virtualHeight ,10,20
controls()
Flip
Wend

Function controls()
If KeyHit(KEY_1)
tVirtualGraphics.Set(640,480)
EndIf
If KeyHit(KEY_2)
tVirtualGraphics.Set(800,600)
EndIf
If KeyHit(KEY_3)
tVirtualGraphics.Set(1024,768)
EndIf
End Function


Type TVirtualGraphics
Global virtualWidth, virtualHeight
Global xRatio!, yRatio!

Function Set(width=640, height=480, scale#=1)
TVirtualGraphics.virtualWidth = width
TVirtualGraphics.virtualHeight = height
TVirtualGraphics.xRatio! = width / Double(GraphicsWidth())
TVirtualGraphics.yRatio! = height / Double(GraphicsHeight())

?Win32
Local dxVer:Byte
Local D3D7Driver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)

If TD3D7Max2DDriver(_max2dDriver) <> Null
dxVer = 7
EndIf


If dxVer <> 0 'dx driver was set, otherwise its GL
Local matrix#[] = [2.0 / (width / scale#), 0.0, 0.0, 0.0,..
0.0, -2.0 / (height / scale#), 0.0, 0.0,..
0.0, 0.0, 1.0, 0.0,..
-1 - (1.0 / width), 1 + (1.0 / height), 1.0, 1.0] ',scale#]

Select dxVer
Case 7
D3D7Driver.device.SetTransform(D3DTS_PROJECTION, matrix)
End Select
Else
?
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, width / scale:Float, height / scale:Float, 0, - 1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
?Win32
EndIf
?
End Function

Function MouseX()
Return (BRL.PolledInput.MouseX() * TVirtualGraphics.xRatio!)
End Function

Function MouseY()
Return (BRL.PolledInput.MouseY() * TVirtualGraphics.yRatio!)
End Function
End Type
Press 1 for (640,480)Press 2 for (800,600)Press 3 for (1024,768)


Chroma(Posted 1+ years ago)

 No one has been able to get this to work in DX9 yet.


_Skully(Posted 1+ years ago)

 Didn't Mark build this into BMax?


xlsior(Posted 1+ years ago)

 Yup, 1.37's 'virtual resolution' commands are using the projection matrix. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal