MovablePlane.cs :  » Game » RealmForge » Axiom » Graphics » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » Axiom » Graphics » MovablePlane.cs
using System;
using Axiom.Core;
using Axiom.MathLib;

namespace Axiom.Graphics{
  
  public interface IDerivedPlaneProvider {

    /// <summary>
    ///    Get the derived plane as transformed by its parent node.
    /// </summary>
    Plane DerivedPlane { get; }
  }

  /// <summary>
  ///    Definition of a Plane that may be attached to a node, and the derived
  ///    details of it retrieved simply.
  /// </summary>
  /// <remarks>
  ///    This plane is not here for rendering purposes, it's to allow you to attach
  ///    planes to the scene in order to have them move and follow nodes on their
  ///    own, which is useful if you're using the plane for some kind of calculation,
  ///    e.g. reflection.
  /// </remarks>
  public class MovablePlane : SceneObject, IDerivedPlaneProvider {
    #region Fields

    /// <summary>
    ///    Plane as transformed by it's parent node.
    /// </summary>
    protected Plane derivedPlane = new Plane();
    /// <summary>
    ///    Cached translation vector.
    /// </summary>
    protected Vector3 lastTranslate;
    /// <summary>
    ///    Cached rotation.
    /// </summary>
    protected Quaternion lastRotate;
    /// <summary>
    ///    Bounding box.
    /// </summary>
    protected AxisAlignedBox nullBB = AxisAlignedBox.Null;
    /// <summary>
    ///    Flag for whether changes have been made to this planes position/rotation.
    /// </summary>
    protected bool isDirty;

    /// <summary>
    ///    Underlying plane representation.
    /// </summary>
    /// <remarks>
    ///    Ogre uses multiple inheritance for this purpose - bah! ;)
    /// </remarks>
    protected Plane containedPlane = new Plane();

    #endregion Fields

    #region Constructor

    /// <summary>
    ///    Constructor.
    /// </summary>
    /// <param name="name">Name of this plane.</param>
    public MovablePlane(string name) {
      this.name = name;
      lastTranslate = Vector3.Zero;
      lastRotate = Quaternion.Identity;
      isDirty = true;
    }

    #endregion Constructor

    #region Properties

    
    public Plane Plane { get { return containedPlane; } }

    /// <summary>
    ///    The plane's distance from the origin.
    /// </summary>
    public float D {
      get {
        return containedPlane.D;
      }
      set {
        containedPlane.D = value;
      }
    }

    /// <summary>
    ///    The direction the plane is facing.
    /// </summary>
    public Vector3 Normal {
      get {
        return containedPlane.Normal;
      }
      set {
        containedPlane.Normal = value;
      }
    }

    /// <summary>
    ///    Get the derived plane as transformed by its parent node.
    /// </summary>
    public Plane DerivedPlane {
      get {
        if(parentNode != null) {
          if(isDirty || 
            !(parentNode.DerivedOrientation == lastRotate && 
            parentNode.DerivedPosition == lastTranslate)) {

            // store off parent position/orientation
            lastRotate = parentNode.DerivedOrientation;
            lastTranslate = parentNode.DerivedPosition;

            // rotate normal
            derivedPlane.Normal = lastRotate * containedPlane.Normal;
            
            // d remains the same in rotation, since rotation happens first
            derivedPlane.D = containedPlane.D;

            // add on the effect of the translation (project onto new normal)
            derivedPlane.D -= derivedPlane.Normal.Dot(lastTranslate);

            isDirty = false;
          }
        }
        else {
          return containedPlane;
        }

        return derivedPlane;
      }
    }

    #endregion Properties

    #region SceneObject Members

    public override Axiom.MathLib.AxisAlignedBox BoundingBox {
      get {
        return nullBB;
      }
    }

    public override float BoundingRadius {
      get {
        return float.PositiveInfinity;
      }
    }

    public override void NotifyCurrentCamera(Camera camera) {
      // dont care
    }

    public override void UpdateRenderQueue(RenderQueue queue) {
      // do nothing
    }

    #endregion SceneObject Members
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.