Raúl
Moderator
 Moderator
| Posts: 444 |  | Karma: 6
|
Re:Entorno de Simulación - 2008/12/03 16:09
Hola, si te fijas en el fichero entities.cs que viene con la distribución de MRDS 2008 (carpeta samples/simulation/entities), verás que en múltiples ocasiones se hace referencia a xna.Input.Mouse para obtener el estado del ratón. Por ejemplo:
| Code: | xna.Input.Mouse.GetState().X,
xna.Input.Mouse.GetState().Y,
|
También te puede resultar útil mirar en la línea 7042, como en el modo edit se detecta un clic de ratón y se hace un trazado de rayos (ray tracing) desde la posición del ratón a la posición 3D de un objetos (evitando ciertos tipos de objeto):
| Code: | // Perform picking if in edit mode and the mouse has been pressed while the window has focus
if (inEditMode && hasMouseFocus &&
mouseState.RightButton == xna.Input.ButtonState.Pressed &&
_cachedMouseState.RightButton == xna.Input.ButtonState.Released &&
Device != null)
{
CameraEntity activeCamera = update.ActiveCamera;
xna.Vector3 cameraPos = activeCamera.World.Translation;
xna.Vector3 mousePos = Device.Viewport.Unproject(new xna.Vector3(xna.Input.Mouse.GetState().X, xna.Input.Mouse.GetState().Y, 1),
activeCamera.ProjectionMatrix, activeCamera.ViewMatrix, xna.Matrix.Identity);
xna.Ray r = new xna.Ray(
cameraPos,
xna.Vector3.Normalize(mousePos - cameraPos)); // Xna is peculiar and rays need normalized directions for bounding spheres
// Picking has trouble with the following types
Type[] typesNotToPick = new Type[] { typeof(SkyEntity), typeof(TerrainEntity), typeof(HeightFieldEntity), typeof(SkyDomeEntity) };
List<TriangleIntersectionRecord> intersectionRecords = SimulationEngine.GlobalInstance.IntersectRayWithoutTypes(r, SimulationEngine.IntersectInvisFlags.SkipDisabledRendering, typesNotToPick);
if (intersectionRecords.Count > 0)
SimulationEngine.SimUI.SelectSingleEntity(intersectionRecords[0].OwnerEntity);
else
SimulationEngine.SimUI.SelectSingleEntity(null);
}
|
Raúl Arrabales Moreno. conscious-robots.com/raul |