Shearing an Image

BlitzMax Forums/BlitzMax Programming/Shearing an Image

therevills(Posted 2012) [#1]
Can you shear an Image with BlitzMax's default command set?


xlsior(Posted 2012) [#2]
There is no built-in command to do that.

However, you can if you do it low-level in OpenGL / DirectX, or using the default commands to create your own function to cut up the image and draw it a line at a time.


therevills(Posted 2012) [#3]
Yeah thats what I thought, thanks.

Looking back in time it looks like BlitzPlus had a nice command: TFormImage

http://www.blitzbasic.com/bpdocs/command.php?name=TFormImage&ref=2d_a-z

Shame this wasnt added to BlitzMax...


ImaginaryHuman(Posted 2012) [#4]
If you split the image into multiple 1-row images you can do it, offset each row.


xlsior(Posted 2012) [#5]
If you split the image into multiple 1-row images you can do it, offset each row.


DrawImageRect()


therevills(Posted 2012) [#6]
I'll have a look, thanks!

Actually, I think I was more after a command which affects the whole viewport too, like SetRotation, SetScale and SetTransform.


ImaginaryHuman(Posted 2012) [#7]
To do it on the viewport you'll have to supply your own projection matrix to OpenGl or DirectX.


therevills(Posted 2012) [#8]
Ah the projection matrix...

So looking into the Bmax modules, SetVirtualResolution calls driver.SetResolution which looks like this for d3d9:

	Method SetResolution( width#,height# )
		Local matrix#[]=[..
		2.0/width, 0.0, 0.0, 0.0,..
		 0.0, -2.0/height, 0.0, 0.0,..
		 0.0, 0.0, 1.0, 0.0,..
		 -1-(1.0/width), 1+(1.0/height), 1.0, 1.0]

		_d3dDev.SetTransform D3DTS_PROJECTION,matrix
	End Method


So that looks like a 4x4 matrix...

DirectX7 has 2 4x4 matrices:

	Method SetResolution( width#,height# )
		Local gw=GraphicsWidth()
		Local gh=GraphicsHeight()
		Local world#[]=[..
			gw/width,0.0,0.0,0.0,..
			0.0,gh/height,0.0,0.0,..
			 0.0,0.0,1.0,0.0,..
			 0.0,0.0,0.0,1.0 ]
		device.SetTransform D3DTS_WORLD,world
		Local proj#[]=[..
			2.0/gw,0.0,0.0,0.0,..
			 0.0,-2.0/gh,0.0,0.0,..
			 0.0,0.0,1.0,0.0,..
			 -1-(1.0/gw),1+(1.0/gh),1.0,1.0]
		device.SetTransform D3DTS_PROJECTION,proj
	End Method


and OpenGL has a nice small method:
	Method SetResolution( width#,height# )
		glMatrixMode GL_PROJECTION
		glLoadIdentity
		glOrtho 0,width,height,0,-1,1
		glMatrixMode GL_MODELVIEW
	End Method


I'll have to have a play and get my matrix cap back on ;)


col(Posted 2012) [#9]
Hi therevills,

2D examples with explanations are in wikipedia...
http://en.wikipedia.org/wiki/Transformation_matrix

EDIT:-
Bear in mind left and right conventions. Looks like some of those examples are in RightHand, Dx in BMax expects LeftHand and OpenGL is RightHand. Just transpose them to swap them over.

Last edited 2012


Captain Wicker (crazy hillbilly)(Posted 2012) [#10]
I thought that said Sharing an image, I was going to tell you to upload it to mediafire! LOL!