bool SceneNode->isIntersected(mouseinput, nodeCamera).
I have found the following steps, but do not know how to do step 3:
source: http://gpwiki.org/index.php/VB:3DmousePart One : Normalizing the Mouse Coordinates
There are a few things that we need to know before we can proceed. We need to know
1. The width of our screen
2. The height of our screen
3. The aspect ratio
4. The field of view (viewing angle of the scene, usually pi/2)
5. The near clipping plane distance
6. The far clipping plane distance
NX = ((X / (Screen_Width / 2)) - 1)
NY = 1 - (Y / (Screen_height / 2))
(Anmerkung: er multipliziert hier noch mit der aspect ratio, das ist m.E. falsch, weil er dann Werte > 1 erhält, oder?
Part Two : Finding Points on the Near + Far Clipping Planes
We need to find two 3D points: One point residing on the near clipping plane and another point sitting on the far clipping plane.
So what we need to do is Multiply the normalized coordinates by tan(fov/2)
Once we have done this we can multiply our ratios by any value of Z (adjacent side) to get points on the near and far clipping planes.
This is because of the formula Tan(theta) * Adjacent side = opposite side. Which should be familar to anyone who has done High School Trigonometry. We just replace Tan(theta) with our own ratios we worked out earlier and Z with our distances between the eye and the near or far planes and viola we've just found two points in 3D space. So what we need to do is Multiply the normalized coordinates by tan(fov/2).
RatioX = tan(fov / 2) * NX
RatioY = tan(fov / 2) * NY
P1.X = ratioX * Near
P1.Y = ratioY * Near
P1.Z = Near
P2.X = ratioX * Far
P2.Y = ratioY * Far
P2.Z = Far
Part Three : Transforming our points inside the viewing frustum into world points
Transforming into world points
A' * P = TransformedP
Where
A' = The inverse view matrix
P = A point within our viewing frustum
'Inverse the view matrix
Dim matInverse As D3DMATRIX
D3DDevice.GetTransform D3DTS_VIEW, matView
D3DXMatrixInverse matInverse, 0, matView
VectorMatrixMultiply P1, P1, matInverse
VectorMatrixMultiply P2, P2, matInverse
public Sub VectorMatrixMultiply
(ByRef vDest As D3DVECTOR, ByRef vSrc As D3DVECTOR, ByRef mat As D3DMATRIX)
dim W as single
W = 1 / ( vSrc.X * mat.m14 + vSrc.Y * mat.m24 + vSrc.Z * mat.m34 + mat.m44 )
vDest.X = (vSrc.X * mat.m11 + vSrc.Y * mat.m21 + vSrc.Z * mat.m31 + mat.m41) * W
vDest.Y = (vSrc.X * mat.m12 + vSrc.Y * mat.m22 + vSrc.Z * mat.m32 + mat.m42) * W
vDest.Z = (vSrc.X * mat.m13 + vSrc.Y * mat.m23 + vSrc.Z * mat.m33 + mat.m43) * W
end sub
Part Four : Creating a Ray
Now we have got our two points we need to turn them into a ray. The point on the near plane will become the starting point for our ray and the point on the far plane will become the end point.
Please help!