🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: free.pl.comp.games.development
Article #202

Direct3d i klikanie na obiekcie

#202
From: ZetX
Date: Tue, 14 Dec 2004 09:28
57 lines
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;
}
Technical Details
Message-ID: <260bc491.0412140128.3b64f8d3@posting.google.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1162ab,80642d26106a5224
X-Google-Attributes: gid1162ab,public
X-Google-Language: POLISH,Latin2
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!not-for-mail
From: zetx@go2.pl (ZetX)
Newsgroups: free.pl.comp.games.development
Subject: Direct3d i klikanie na obiekcie
Date: 14 Dec 2004 01:28:51 -0800
Organization: http://groups.google.com
Lines: 57
Message-ID: <260bc491.0412140128.3b64f8d3@posting.google.com>
NNTP-Posting-Host: 195.187.252.6
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1103016531 30239 127.0.0.1 (14 Dec 2004 09:28:51 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 14 Dec 2004 09:28:51 +0000 (UTC)