public PlaneBoundedVolume getPlaneBoundedVolume() { PlaneBoundedVolume ret = new PlaneBoundedVolume(OgrePINVOKE.Frustum_getPlaneBoundedVolume(swigCPtr), true); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public virtual PlaneBoundedVolume _getNearClipVolume(Camera cam) { PlaneBoundedVolume ret = new PlaneBoundedVolume(OgrePINVOKE.Light__getNearClipVolume(swigCPtr, Camera.getCPtr(cam)), false); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public PlaneBoundedVolume getCameraToViewportBoxVolume(float screenLeft, float screenTop, float screenRight, float screenBottom) { PlaneBoundedVolume ret = new PlaneBoundedVolume(OgrePINVOKE.Camera_getCameraToViewportBoxVolume__SWIG_1(swigCPtr, screenLeft, screenTop, screenRight, screenBottom), true); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public SWIGTYPE_p_std__pairT_bool_float_t intersects(PlaneBoundedVolume p) { SWIGTYPE_p_std__pairT_bool_float_t ret = new SWIGTYPE_p_std__pairT_bool_float_t(OgrePINVOKE.Ray_intersects__SWIG_1(swigCPtr, PlaneBoundedVolume.getCPtr(p)), true); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
// Check if a portal intersects a plane bounded volume // NOTE: This check is not exact. // NOTE: UNTESTED as of 5/30/07 (EC) public bool intersects(PlaneBoundedVolume pbv) { // Only check if portal is open if (this.mOpen) { switch (this.mType) { case PORTAL_TYPE.PORTAL_TYPE_QUAD: { // first check sphere of the portal if (!pbv.Intersects(this.mDerivedSphere)) { return(false); } // if the portal corners are all outside one of the planes of the pbv, // then the portal does not intersect the pbv. (this can result in // some false positives, but it's the best I can do for now) foreach (Plane plane in pbv.planes) { bool allOutside = true; for (int i = 0; i < 4; i++) { if (plane.GetSide(this.mDerivedCorners[i]) != pbv.outside) { allOutside = false; } } if (allOutside) { return(false); } } } break; case PORTAL_TYPE.PORTAL_TYPE_AABB: { var aabb = new AxisAlignedBox(this.mDerivedCorners[0], this.mDerivedCorners[1]); if (!pbv.Intersects(aabb)) { return(false); } } break; case PORTAL_TYPE.PORTAL_TYPE_SPHERE: if (!pbv.Intersects(this.mDerivedSphere)) { return(false); } break; } } return(false); }
/// <summary> /// private method for selection object that creates a box from the SelectionRectangle, stop variable is passed in /// </summary> /// <param name="first">Vector2</param> /// <param name="second">Vector2</param> private void PerformSelectionWithSelectionBox(Math.Vector2 first, Math.Vector2 second) { Log("MouseSelector: " + this._name + " performing selection."); float left = first.x, right = second.x, top = first.y, bottom = second.y; if (left > right) { Utility.Swap(ref left, ref right); } if (top > bottom) { Utility.Swap(ref top, ref bottom); } if ((right - left) * (bottom - top) < 0.0001) { return; } Ray topLeft = this._Camera.GetCameraToViewportRay(left, top); Ray topRight = this._Camera.GetCameraToViewportRay(right, top); Ray bottomLeft = this._Camera.GetCameraToViewportRay(left, bottom); Ray bottomRight = this._Camera.GetCameraToViewportRay(right, bottom); var vol = new PlaneBoundedVolume(); vol.planes.Add(new Math.Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3))); // front plane vol.planes.Add(new Math.Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100))); // top plane vol.planes.Add(new Math.Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100))); // left plane vol.planes.Add(new Math.Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100))); // bottom plane vol.planes.Add(new Math.Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100))); // right plane var volList = new PlaneBoundedVolumeList(); volList.Add(vol); PlaneBoundedVolumeListSceneQuery volQuery; volQuery = Root.Instance.SceneManager.CreatePlaneBoundedVolumeQuery(new PlaneBoundedVolumeList()); volQuery.Volumes = volList; SceneQueryResult result = volQuery.Execute(); foreach (MovableObject obj in result.objects) { SelectObject(obj); } }
/** Checks how the axis aligned box intersects with the plane bounded volume */ private static Intersection intersect(PlaneBoundedVolume one, AxisAlignedBox two) { // Null box? if (two.IsNull) { return(Intersection.OUTSIDE); } // Infinite box? if (two.IsInfinite) { return(Intersection.INTERSECT); } // Get centre of the box Vector3 centre = two.Center; // Get the half-size of the box Vector3 halfSize = two.HalfSize; // For each plane, see if all points are on the negative side // If so, object is not visible. // If one or more are, it's partial. // If all aren't, full bool all_inside = true; foreach (Plane plane in one.planes) { PlaneSide side = plane.GetSide(centre, halfSize); if (side == one.outside) { return(Intersection.OUTSIDE); } if (side == PlaneSide.Both) { all_inside = false; } } if (all_inside) { return(Intersection.INSIDE); } else { return(Intersection.INTERSECT); } }
/// <summary> /// Casts the plane selection and selects all objects inside the SelectionRectangle. /// Hitted objects sends to the GameObjectManager (OnLeftClick). /// </summary> /// <param name="first">The firts corner.</param> /// <param name="second">The second corner.</param> private void PerformSelection(Vector2 first, Vector2 second) { float left = first.x, right = second.x, top = first.y, bottom = second.y; if (left > right) { Swap(ref left, ref right); } if (top > bottom) { Swap(ref top, ref bottom); } if ((right - left) * (bottom - top) < 0.0001) { return; } Camera c = Game.SceneManager.GetCamera("myCam"); Ray topLeft = c.GetCameraToViewportRay(left, top); Ray topRight = c.GetCameraToViewportRay(right, top); Ray bottomLeft = c.GetCameraToViewportRay(left, bottom); Ray bottomRight = c.GetCameraToViewportRay(right, bottom); PlaneBoundedVolume vol = new PlaneBoundedVolume(); vol.planes.Add(new Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3))); // Front plane vol.planes.Add(new Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100))); // Top plane vol.planes.Add(new Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100))); // Left plane vol.planes.Add(new Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100))); // Bottom plane vol.planes.Add(new Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100))); // Right plane PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList(); volList.Add(vol); PlaneBoundedVolumeListSceneQuery volQuery = Game.SceneManager.CreatePlaneBoundedVolumeQuery(volList); SceneQueryResult result = volQuery.Execute(); List <MovableObject> list = new List <MovableObject>(result.movables); GameObjectManager.GetInstance().OnLeftClick(list); Game.SceneManager.DestroyQuery(volQuery); }
public void performSelection(Vector2 first, Vector2 second) { float left = first.x, right = second.x, top = first.y, bottom = second.y; if (left > right) swap(ref left, ref right); if (top > bottom) swap(ref top, ref bottom); if ((right - left) * (bottom - top) < 0.0001) { Program.PerformSingleSelection(); return; } Ray topLeft = _camera.GetCameraToViewportRay(left, top); Ray topRight = _camera.GetCameraToViewportRay(right, top); Ray bottomLeft = _camera.GetCameraToViewportRay(left, bottom); Ray bottomRight = _camera.GetCameraToViewportRay(right, bottom); PlaneBoundedVolume vol = new PlaneBoundedVolume(); vol.planes.Add(new Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3))); // front plane vol.planes.Add(new Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100))); // top plane vol.planes.Add(new Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100))); // left plane vol.planes.Add(new Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100)));// bottom plane vol.planes.Add(new Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100))); // right plane PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList(); volList.Add(vol); PlaneBoundedVolumeListSceneQuery volQuery = Program.GetSceneManager().CreatePlaneBoundedVolumeQuery(volList); SceneQueryResult result = volQuery.Execute(); foreach (var obj in result.movables) { if (obj.MovableType == "Entity") Program.selectUnit(obj); } Program.GetSceneManager().DestroyQuery(volQuery); }
public override void FindNodes(PlaneBoundedVolume t, ref List <PCZSceneNode> list, List <Portal> visitedPortals, bool includeVisitors, bool recurseThruPortals, PCZSceneNode exclude) { // if this zone has an enclosure, check against the enclosure AABB first if (null != mEnclosureNode) { if (!t.Intersects(mEnclosureNode.WorldAABB)) { // AABB of zone does not intersect t, just return. return; } } // use the Octree to more efficiently find nodes intersecting the plane bounded volume this.rootOctree._findNodes(t, ref list, exclude, includeVisitors, false); // if asked to, recurse through portals if (recurseThruPortals) { foreach (Portal portal in mPortals) { // check portal versus boundign box if (portal.intersects(t)) { // make sure portal hasn't already been recursed through if (!visitedPortals.Contains(portal)) { // save portal to the visitedPortals list visitedPortals.Add(portal); // recurse into the connected zone portal.getTargetZone().FindNodes(t, ref list, visitedPortals, includeVisitors, recurseThruPortals, exclude); } } } } }
public abstract void FindNodes(PlaneBoundedVolume t, ref List <PCZSceneNode> list, List <Portal> visitedPortals, bool includeVisitors, bool recurseThruPortals, PCZSceneNode exclude);
/// <summary> /// Tests whether this ray intersects the given PlaneBoundedVolume. /// </summary> /// <param name="volume"></param> /// <returns> /// Struct containing info on whether there was a hit, and the distance from the /// origin of this ray where the intersect happened. /// </returns> public IntersectResult Intersects(PlaneBoundedVolume volume) { return(Utility.Intersects(this, volume)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PlaneBoundedVolume obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
/// <summary> /// Casts the plane selection and selects all objects inside the SelectionRectangle. /// Hitted objects sends to the GameObjectManager (OnLeftClick). /// </summary> /// <param name="first">The firts corner.</param> /// <param name="second">The second corner.</param> private void PerformSelection(Vector2 first, Vector2 second) { float left = first.x, right = second.x, top = first.y, bottom = second.y; if (left > right) Swap(ref left, ref right); if (top > bottom) Swap(ref top, ref bottom); if ((right - left) * (bottom - top) < 0.0001) return; Camera c = Game.SceneManager.GetCamera("myCam"); Ray topLeft = c.GetCameraToViewportRay(left, top); Ray topRight = c.GetCameraToViewportRay(right, top); Ray bottomLeft = c.GetCameraToViewportRay(left, bottom); Ray bottomRight = c.GetCameraToViewportRay(right, bottom); PlaneBoundedVolume vol = new PlaneBoundedVolume(); vol.planes.Add(new Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3))); // Front plane vol.planes.Add(new Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100))); // Top plane vol.planes.Add(new Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100))); // Left plane vol.planes.Add(new Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100)));// Bottom plane vol.planes.Add(new Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100))); // Right plane PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList(); volList.Add(vol); PlaneBoundedVolumeListSceneQuery volQuery = Game.SceneManager.CreatePlaneBoundedVolumeQuery(volList); SceneQueryResult result = volQuery.Execute(); List<MovableObject> list = new List<MovableObject>(result.movables); GameObjectManager.GetInstance().OnLeftClick(list); Game.SceneManager.DestroyQuery(volQuery); }
public override void FindNodes(PlaneBoundedVolume t, ref List <PCZSceneNode> list, List <Portal> visitedPortals, bool includeVisitors, bool recurseThruPortals, PCZSceneNode exclude) { // if this zone has an enclosure, check against the enclosure AABB first if (null != mEnclosureNode) { if (!t.Intersects(mEnclosureNode.WorldAABB)) { // AABB of zone does not intersect t, just return. return; } } // check nodes at home in this zone foreach (PCZSceneNode pczsn in mHomeNodeList) { if (pczsn != exclude) { // make sure node is not already in the list (might have been added in another // zone it was visiting) if (!list.Contains(pczsn)) { bool nsect = t.Intersects(pczsn.WorldAABB); if (nsect) { list.Add(pczsn); } } } } if (includeVisitors) { // check visitor nodes foreach (PCZSceneNode pczsn in mVisitorNodeList) { if (pczsn != exclude) { // make sure node is not already in the list (might have been added in another // zone it was visiting) if (!list.Contains(pczsn)) { bool nsect = t.Intersects(pczsn.WorldAABB); if (nsect) { list.Add(pczsn); } } } } } // if asked to, recurse through portals if (recurseThruPortals) { foreach (Portal portal in mPortals) { // check portal versus boundign box if (portal.intersects(t)) { // make sure portal hasn't already been recursed through if (!visitedPortals.Contains(portal)) { // save portal to the visitedPortals list visitedPortals.Add(portal); // recurse into the connected zone portal.getTargetZone().FindNodes(t, ref list, visitedPortals, includeVisitors, recurseThruPortals, exclude); } } } } }
/// <summary> /// Internal method for calculating the clip volumes outside of the /// frustum which can be used to determine which objects are casting /// shadow on the frustum as a whole. /// </summary> /// <remarks> /// Each of the volumes is a pyramid for a point/spot light and /// a cuboid for a directional light. /// </remarks> /// <param name="camera"></param> /// <returns></returns> internal List <PlaneBoundedVolume> GetFrustumClipVolumes(Camera camera) { // Homogenous light position Vector4 lightPos = GetAs4DVector(); // 3D version (not the same as DerivedPosition, is -direction for // directional lights) Vector3 lightPos3 = new Vector3(lightPos.x, lightPos.y, lightPos.z); Vector3 lightDir; Vector3[] clockwiseVerts = new Vector3[4]; Matrix4 eyeToWorld = camera.ViewMatrix.Inverse(); // Get worldspace frustum corners Vector3[] corners = camera.WorldSpaceCorners; bool infiniteViewDistance = (camera.Far == 0); frustumClipVolumes.Clear(); for (int n = 0; n < 6; n++) { FrustumPlane frustumPlane = (FrustumPlane)n; // skip far plane if infinite view frustum if (infiniteViewDistance && (frustumPlane == FrustumPlane.Far)) { continue; } Plane plane = camera[frustumPlane]; Vector4 planeVec = new Vector4(plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D); // planes face inwards, we need to know if light is on negative side float d = planeVec.Dot(lightPos); if (d < -1e-06f) { // Ok, this is a valid one // clockwise verts mean we can cross-product and always get normals // facing into the volume we create frustumClipVolumes.Add(new PlaneBoundedVolume()); PlaneBoundedVolume vol = (PlaneBoundedVolume)frustumClipVolumes[frustumClipVolumes.Count - 1]; switch (frustumPlane) { case (FrustumPlane.Near): clockwiseVerts[0] = corners[3]; clockwiseVerts[1] = corners[2]; clockwiseVerts[2] = corners[1]; clockwiseVerts[3] = corners[0]; break; case (FrustumPlane.Far): clockwiseVerts[0] = corners[7]; clockwiseVerts[1] = corners[6]; clockwiseVerts[2] = corners[5]; clockwiseVerts[3] = corners[4]; break; case (FrustumPlane.Left): clockwiseVerts[0] = corners[2]; clockwiseVerts[1] = corners[6]; clockwiseVerts[2] = corners[5]; clockwiseVerts[3] = corners[1]; break; case (FrustumPlane.Right): clockwiseVerts[0] = corners[7]; clockwiseVerts[1] = corners[3]; clockwiseVerts[2] = corners[0]; clockwiseVerts[3] = corners[4]; break; case (FrustumPlane.Top): clockwiseVerts[0] = corners[0]; clockwiseVerts[1] = corners[1]; clockwiseVerts[2] = corners[5]; clockwiseVerts[3] = corners[4]; break; case (FrustumPlane.Bottom): clockwiseVerts[0] = corners[7]; clockwiseVerts[1] = corners[6]; clockwiseVerts[2] = corners[2]; clockwiseVerts[3] = corners[3]; break; } // Build a volume // Iterate over world points and form side planes Vector3 normal; for (int i = 0; i < 4; i++) { // Figure out light dir lightDir = lightPos3 - (clockwiseVerts[i] * lightPos.w); // Cross with anticlockwise corner, therefore normal points in // Note: C++ mod returns 3 for the first case where C# returns -1 int test = i > 0 ? ((i - 1) % 4) : 3; // Cross with anticlockwise corner, therefore normal points in normal = (clockwiseVerts[i] - clockwiseVerts[test]).Cross(lightDir); normal.Normalize(); // NB last param to Plane constructor is negated because it's -d vol.planes.Add(new Plane(normal, normal.Dot(clockwiseVerts[i]))); } // Now do the near plane (this is the plane of the side we're // talking about, with the normal inverted (d is already interpreted as -ve) vol.planes.Add(new Plane(-plane.Normal, plane.D)); // Finally, for a point/spot light we can add a sixth plane // This prevents false positives from behind the light if (type != LightType.Directional) { // re-use our own plane normal // remember the -d negation in plane constructor vol.planes.Add(new Plane(plane.Normal, plane.Normal.Dot(lightPos3))); } } } return(frustumClipVolumes); }
public void _findNodes(PlaneBoundedVolume t, ref List <PCZSceneNode> list, PCZSceneNode exclude, bool includeVisitors, bool full) { if (!full) { AxisAlignedBox obox; _getCullBounds(out obox); Intersection isect = intersect(t, obox); if (isect == Intersection.OUTSIDE) { return; } full = (isect == Intersection.INSIDE); } foreach (PCZSceneNode on in this.nodeList.Values) { if (on != exclude && (on.HomeZone == this.zone || includeVisitors)) { if (full) { // make sure the node isn't already on the list list.Add(on); } else { Intersection nsect = intersect(t, on.WorldAABB); if (nsect != Intersection.OUTSIDE) { // make sure the node isn't already on the list list.Add(on); } } } } Octree child; if ((child = this.Children[0, 0, 0]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[1, 0, 0]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[0, 1, 0]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[1, 1, 0]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[0, 0, 1]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[1, 0, 1]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[0, 1, 1]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } if ((child = this.Children[1, 1, 1]) != null) { child._findNodes(t, ref list, exclude, includeVisitors, full); } }
public void getCameraToViewportBoxVolume(float screenLeft, float screenTop, float screenRight, float screenBottom, PlaneBoundedVolume outVolume) { OgrePINVOKE.Camera_getCameraToViewportBoxVolume__SWIG_3(swigCPtr, screenLeft, screenTop, screenRight, screenBottom, PlaneBoundedVolume.getCPtr(outVolume)); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } }