Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Object Picking again

Author
Message
thierry st malo
18
Years of Service
User Offline
Joined: 7th Nov 2005
Location: Saint-Malo, France
Posted: 19th Jan 2007 09:02
Hi, everybody!
Still having trouble with DGDK.NET\'s oDB3D.PickObject(), I had decided to write by myself an object picking routine, the basic logic being (as I see it) rather simple. But as you will see from the following code, obviously there must be something that I misunderstand in the oDBMath object, namely the way in which 4D vectors and matrices are dealt with.

This is VB Express code, the variables being exactly what their name implies.

\'---------- X and Y, the Microsoft Windows coordinates of the picked point, are transformed
\' into Dx and DY, regular and normalized screen coordinates with the origin
\' at the center of the screen.

HSW = MyWin.PictureBox1.ClientSize.Width / 2
HSH = MyWin.PictureBox1.ClientSize.Height / 2
Aspect = HSW / HSH

DX = X - HSW
DY = HSH - Y
DX = DX / HSW
DY = DY / HSH
DX = DX / Aspect

\'---------- DX and DY are scaled according to the camera\'s FOV.

FOV = Radians(MyCamera.FOV) / 2

DX = DX * Math.Tan(FOV)
DY = DY * Math.Tan(FOV)

\'---------- DX and DY are used to create P1 and P2, 3D points with view (frustum) coordinates.

With P1
.X = DX * MyCamera.Near
.Y = DY * MyCamera.Near
.Z = MyCamera.Near
End With

With P2
.X = DX * MyCamera.Far
.Y = DY * MyCamera.Far
.Z = MyCamera.Far
End With

\'---------- At this point, everything is fine. I want to transform P1 and P2 using the inverse
\' of the view matrix, thus arriving, hopefully, at 3D world coordinates.
\' But here I get into trouble :-( I don\'t know why.

bOK = oDBMath.MakeVector4(1)
oDBMath.SetVector4(1, P1.X, P1.Y, P1.Z, 1)
bOK = oDBMath.MakeVector4(2)
oDBMath.SetVector4(2, P2.X, P2.Y, P2.Z, 1)

bOK = oDBMath.MakeMatrix4(1)
oDBMath.ViewMatrix4(1)
bOK = oDBMath.MakeMatrix4(2)
N = CInt(oDBMath.InverseMatrix4(2, 1))

If N = 0 Then
MsgBox(IDCS_027, IDC_WARNING, IDCS_024)
Return -1
End If

bOK = oDBMath.MakeVector4(3)
bOK = oDBMath.MakeVector4(4)
oDBMath.TransformVector4(3, 1, 2)
oDBMath.TransformVector4(4, 2, 2)

With P1
.X = oDBMath.XVector4(3)
.Y = oDBMath.YVector4(3)
.Z = oDBMath.ZVector4(3)
End With

With P2
.X = oDBMath.XVector4(4)
.Y = oDBMath.YVector4(4)
.Z = oDBMath.ZVector4(4)
End With

\'---------- At this point P1 and P2 ALWAYS contain (0,0,0), whatever values had been in the original X and Y.

Can you help?
Thanks in advance,
Thierry

Login to post a reply

Server time is: 2024-06-26 09:36:45
Your offset time is: 2024-06-26 09:36:45