Thread View: free.pl.comp.games.development
1 messages
1 total messages
Started by ZetX
Tue, 14 Dec 2004 09:28
Direct3d i klikanie na obiekcie
Author: ZetX
Date: Tue, 14 Dec 2004 09:28
Date: Tue, 14 Dec 2004 09:28
57 lines
2362 bytes
2362 bytes
// przyklad w oparciu o: C# i Managed DirectX, Mesh'e reprezentujace siatki
// obiektow renderowanych (jak bedziesz wczytywal .x to pewnie uzyjesz Mesh'y)
//
// deviceD3D jest typu Microsoft.DirectX.Direct3D.Device
// Object3D jest to klasa zawierajaca m.in. Mesh'a
// (Microsoft.DirectX.Direct3D.Mesh)
// xPos i yPos - wspol. kursora myszki
// renderObjects moze byc typu System.Collections.ArrayList
// (zawierac renderowane obiekty juz po przetworzeniu algorytmem sprawdzania
// ich "widocznosci")
//
// pamietaj o using'ach: Microsoft.DirectX, Microsoft.DirectX.Direct3D
bool CheckMouseHit(int xPos, int yPos)
{
IntersectInformation intInformation = new IntersectInformation();
float dist = float.MaxValue;
Object3D object3D = null;
Vector3 s, d, rPosition, rDirection;
foreach ( Object3D obj3D in renderObjects )
{
s = Vector3.Unproject(new Vector3( xPos, yPos, 0),
deviceD3D.Viewport,
deviceD3D.Transform.Projection,
deviceD3D.Transform.View,
deviceD3D.Transform.World );
d = Vector3.Unproject(new Vector3( xPos, yPos, 1),
deviceD3D.Viewport,
deviceD3D.Transform.Projection,
deviceD3D.Transform.View,
deviceD3D.Transform.World );
rPosition = s;
rDirection = Vector3.Normalize(d-s);
if ( obj3D.Mesh.Intersect( rPosition,
rDirection,
ref intInformation ) )
{
if ( intInformation.Dist < dist )
{
dist = intInformation.Dist;
object3D = obj3D;
}
}
}
if ( object3D != null )
{
// mamy obiekt i teraz "cos" trzeba z nim zrobic :)
return true;
}
return false;
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads