Ejemplo n.º 1
0
        private void GetEdgePoints(BaseCamera viewerCamera, ConvexVolume volume, out Vector3 LBN, out Vector3 RTF)
        {
            Vector3 ViewerPosition = viewerCamera.GetEyeVector();

            // Find left and right edges
            Vector3 IntersectionPointC = GetLeftRightIntersectionPoint(ViewerPosition, volume.FarPlane, volume.LeftPlane);
            Vector3 IntersectionPointB = GetLeftRightIntersectionPoint(ViewerPosition, volume.FarPlane, volume.RightPlane);
            // Find top and bottom edges
            Vector3 IntersectionPointBottom = GetTopBottomIntersectionPoint(ViewerPosition, volume.FarPlane, volume.BottomPlane);
            Vector3 IntersectionPointTop    = GetTopBottomIntersectionPoint(ViewerPosition, volume.FarPlane, volume.TopPlane);

            float left, right, top, bottom, near, far;
            // left
            Dictionary <float, Vector3> projectedValues = new Dictionary <float, Vector3>();

            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, -RightVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, -RightVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -RightVector), ViewerPosition);
            left = projectedValues[projectedValues.Keys.Max()].X;

            // right
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, RightVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, RightVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, RightVector), ViewerPosition);
            right = projectedValues[projectedValues.Keys.Max()].X;

            // top
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointTop, UpVector), IntersectionPointTop);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointBottom, UpVector), IntersectionPointBottom);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, UpVector), ViewerPosition);
            top = projectedValues[projectedValues.Keys.Max()].Y;

            // bottom
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointTop, -UpVector), IntersectionPointTop);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointBottom, -UpVector), IntersectionPointBottom);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -UpVector), ViewerPosition);
            bottom = projectedValues[projectedValues.Keys.Max()].Y;

            // far
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, ForwardVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, ForwardVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, ForwardVector), ViewerPosition);
            far = projectedValues[projectedValues.Keys.Max()].Z;

            // near
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, -ForwardVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, -ForwardVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -ForwardVector), ViewerPosition);
            near = projectedValues[projectedValues.Keys.Max()].Z;

            LBN = new Vector3(left, bottom, near);
            RTF = new Vector3(right, top, far);
        }
Ejemplo n.º 2
0
        public static bool IsPointInsideConvexVolume(ConvexVolume convexVolume, Vector3 point)
        {
            bool bResult = false;

            for (Int32 i = 0; i < 6; i++)
            {
                bResult = IsPointIsidePlane(convexVolume[i], point, convexVolume.relativePosition);
                if (!bResult)
                {
                    break;
                }
            }
            return(bResult);
        }
Ejemplo n.º 3
0
        public Matrix4 CreateOrthographicProjection(BaseCamera viewerCamera, ref Matrix4 projectionMatrix)
        {
            Matrix4 result = Matrix4.Identity;
            Matrix4 ViewProjectionMatrix = Matrix4.Identity;

            ViewProjectionMatrix *= viewerCamera.GetViewMatrix();
            ViewProjectionMatrix *= projectionMatrix;

            ConvexVolume cameraVolume = new ConvexVolume(ViewProjectionMatrix);
            Vector3      lbn, rtf;

            GetEdgePoints(viewerCamera, cameraVolume, out lbn, out rtf);

            result = Matrix4.CreateOrthographic(rtf.X - lbn.X, 100, 1, 400);
            return(result);
        }
Ejemplo n.º 4
0
        void PickUpThing(ConvexVolume cv)
        {
            PickUp pu = cv.mOwner.GetComponent(typeof(PickUp)) as PickUp;

            pu.StateChange(PickUp.State.WaitingRespawn, 1);

            StaticMeshComp smc = pu.mOwner.GetComponent(typeof(StaticMeshComp)) as StaticMeshComp;

            StaticMesh sm = smc.mDrawObject as StaticMesh;

            int numParts = sm.GetNumParts();

            for (int i = 0; i < numParts; i++)
            {
                sm.SetPartVisible(i, false);
            }
        }
Ejemplo n.º 5
0
        //called once before render with accumulated delta
        //do all once per render style updates in here
        internal void RenderUpdate(float msDelta)
        {
            if (msDelta <= 0f)
            {
                return;                 //can happen if fixed time and no remainder
            }

            //check pvs against entities
            mVisibleSMC.Clear();
            foreach (StaticMeshComp smc in mStaticComps)
            {
                Vector3 smPos = smc.mPO.GetPosition();

                if (mZone.IsVisibleFrom(mGD.GCam.Position, smPos))
                {
                    mVisibleSMC.Add(smc);
                }
            }

            //update meshlighting for visible
            foreach (StaticMeshComp smc in mVisibleSMC)
            {
                MeshLighting ml = smc.mOwner.GetComponent(typeof(MeshLighting)) as MeshLighting;
                ConvexVolume cv = smc.mOwner.GetComponent(typeof(ConvexVolume)) as ConvexVolume;

                ml.Update(msDelta / 1000f, smc.mPO.GetPosition() + cv.SizeY * 0.5f);
            }

            mZoneDraw.Update(msDelta);

            mZoneMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);

            if (mStaticMats != null)
            {
                mStaticMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);
            }
            if (mPMats != null)
            {
                mPMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);
            }

            mShadKeeper.StartNewFrame();
            mShadKeeper.ComputeBatch(mPMob.GetEyePos());
        }