Пример #1
0
 public EELight(DVector3 Position, Vector3 Color, float Distance, float MaxLife)
 {
     this.Position = Position;
     this.Color = Color;
     this.Distance = Distance;
     this.MaxLife = MaxLife;
 }
        public int Accept(DVector3 data, TType type, Title x)
        {
            var v = data.Value;

            SetTitleValue(x, $"{v.X},{v.Y},{v.Z}");
            return(1);
        }
Пример #3
0
 public DVector3 Translate(DVector3 position)
 {
     x += position.x;
     y += position.y;
     z += position.z;
     return(this);
 }
Пример #4
0
        public void SumSmokeTest()
        {
            var a = new DVector3(1, 0, 0);
            var b = new DVector3(1, 1, 1);

            Assert.Equal(new DVector3(2, 1, 1), a + b);
        }
Пример #5
0
    // Start is called before the first frame update
    void SetParameters()
    {
        // Calculate the master scale based on the state of the body:
        L_dir       = DVector3.ToUnity(Body.L.normalized);
        MasterScale = Vector3.Dot(L_dir, DVector3.ToUnity(Body.Omega));

        // The angular momentum is just a directional display, so its length is arbitrarty.
        L.SetLength(1.5f);

        Debug.Log(string.Format("MasterScale {0},", MasterScale));

        OrientCamera();
        OrientPlanesAndL();
        PositionPlanes();

        // For a given angular velocity in body-fixed-corrdinates, the energy is:
        // 2E = w_x^2Ix + w_y^2Iy+w_z^2I_z
        var     body_i          = DVector3.ToUnity(Body.I);
        float   E               = (float)Body.Energy;
        Vector3 ellipsoid_scale = new Vector3(Mathf.Sqrt(2 * E / body_i.x),
                                              Mathf.Sqrt(2 * E / body_i.y),
                                              Mathf.Sqrt(2 * E / body_i.z));

        //Debug.Log(string.Format("ellipsoid_scale ({0},{1},{2})", ellipsoid_scale.x, ellipsoid_scale.y, ellipsoid_scale.z));

        ellipsoid_scale *= 1 / MasterScale;
        InertiaEllipsoid.transform.localScale = ellipsoid_scale * 2;         // Remember unity sphere has radius 1/2.

        //float f = EvalEllipsoid(Body.BodyOmega(), ellipsoid_scale);
        //Debug.Log(string.Format("Curr ellipse eq value: {0}", f));

        AngularVelocityTrail.enabled = false;
        AngularVelocityTrail.Clear();
    }
Пример #6
0
 public IntVector3 WorldPointToRegion(DVector3 worldPosition)
 {
     return(new IntVector3(
                (int)(worldPosition.X / _regionSize),
                (int)(worldPosition.Y / _regionSize),
                (int)(worldPosition.Z / _regionSize)));
 }
Пример #7
0
 private DVector3 GetPointOnCube(DVector3 vector, DVector3 scale, DVector3 translation, Matrix4x4 rotation)
 {
     vector.Scale(scale);
     vector = (DVector3)rotation.MultiplyPoint((Vector3)vector);
     vector.Translate(position);
     return(vector);
 }
Пример #8
0
    static bool ExtentsFromInertia(DVector3 inertia, out DVector3 extents)
    {
        // Note that is very easy to pick inertia values that don't coincide with an ellipsoidal
        // object.
        const targ_type min_extent2 = .01f * .01f;

        bool success = true;
        var  ex2     = (inertia.y + inertia.z - inertia.x) * 5 / 2;

        if (ex2 < min_extent2)
        {
            ex2     = min_extent2;
            success = false;
        }
        var ey2 = (inertia.x + inertia.z - inertia.y) * 5 / 2;

        if (ey2 < min_extent2)
        {
            ey2     = min_extent2;
            success = false;
        }
        var ez2 = (inertia.x + inertia.y - inertia.z) * 5 / 2;

        if (ez2 < min_extent2)
        {
            ez2     = min_extent2;
            success = false;
        }

        extents = new DVector3(Math.Sqrt(ex2), Math.Sqrt(ey2), Math.Sqrt(ez2));
        return(success);
    }
Пример #9
0
 public DVector3 Scale(DVector3 scale)
 {
     x *= scale.x;
     y *= scale.y;
     z *= scale.z;
     return(this);
 }
Пример #10
0
    /// <summary>
    /// Updates the object position.
    /// </summary>
    /// <param name="instance">Instance.</param>
    /// <param name="instanceLocation">Instance location.</param>
    /// <param name="instanceOptions">Instance options.</param>
    /// <param name="deviceLocation">Device location.</param>
    public void UpdateObjectPosition(
        ARLocationManagerEntry entry,
        Location deviceLocation,
        DVector3 delta,
        bool forceDisableSmooth = false
        )
    {
        var instance         = entry.instance;
        var instanceLocation = entry.location;
        var instanceOptions  = entry.options;
        var smoothMove       = instance.GetComponent <SmoothMove>();

        var useSmoothMove = !(smoothMove == null || forceDisableSmooth || locationProvider.provider.isRawTime());


        if (useSmoothMove)
        {
            smoothMove.Target = Location.GetGameObjectPositionForLocation(
                Camera.main.transform, deviceLocation, instanceLocation, instanceOptions.isHeightRelative
                );
        }
        else
        {
            Location.PlaceGameObjectAtLocation(
                instance.transform, Camera.main.transform, deviceLocation, instanceLocation, instanceOptions.isHeightRelative
                );
        }
    }
Пример #11
0
        public void GenerateTest(string sData, DVector3 PositionMeters)
        {
            List <List <Vector3> > segments = new List <List <Vector3> >();

            List <Vector3> list = new List <Vector3>();

            list.Add(new Vector3(0, 0, 0));
            list.Add(new Vector3(100, 0, 0));
            list.Add(new Vector3(200, 0, 0));

            segments.Add(list);

            List <Vector3> list2 = new List <Vector3>();

            list2.Add(new Vector3(65, 0, 0));
            list2.Add(new Vector3(55, 0, 100));
            list2.Add(new Vector3(45, 0, 200));

            segments.Add(list2);

            GameObject     go = new GameObject("test");
            MassiveFeature f  = go.AddComponent <MassiveFeature>();

            f.SetSegments(segments);
            go.transform.parent        = this.transform;
            go.transform.localPosition = Vector3.zero;
            MeshData md = new MeshData();

            Run(segments, md, 20);

            // Create the mesh
            CreateGameObject(md, go, "minor_road");
        }
Пример #12
0
        public Vertex(DVector3 point)
        {
            Polygon = new List <Polygon>();
            _Point  = new DVector4(point, 1.0);

            _Normal = DVector4.Zero;
        }
Пример #13
0
    // Update is called once per frame
    void Update()
    {
        _acceleration = SumForce() / Mass;

        _velocity             = _acceleration * Time.deltaTime;
        _ptransform.position += Velocity * Time.deltaTime;
    }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="lonLat"></param>
        /// <returns></returns>
        bool ScreenToSpherical(float x, float y, out DVector2 lonLat)
        {
            var w = viewportWidth;
            var h = viewportHeight;

            var nearPoint = new DVector3(x, y, frustumZNear);
            var farPoint  = new DVector3(x, y, frustumZFar);


            var vm  = DMatrix.LookAtRH(cameraPosition, DVector3.Zero, DVector3.UnitY);
            var mVP = vm * projMatrix;

            var near = DVector3.Unproject(nearPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);
            var far  = DVector3.Unproject(farPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);

            lonLat = DVector2.Zero;

            DVector3[] res;

            if (LineIntersection(near, far, Config.earthRadius, out res))
            {
                CartesianToSpherical(res[0], out lonLat.X, out lonLat.Y);
                return(true);
            }

            return(false);
        }
Пример #15
0
        DVector2 CartesianToSpherical(DVector3 cart)
        {
            double lon, lat;

            CartesianToSpherical(cart, out lon, out lat);
            return(new DVector2(lon, lat));
        }
Пример #16
0
    // Update is called once per frame
    void Update()
    {
        var body_l = Target.BodyL();
        var offset = body_l * Scale;

        transform.localPosition = DVector3.ToUnity(offset);
    }
Пример #17
0
    // Start is called before the first frame update
    void SetParameters()
    {
        // The overall scale of the display is set so that |L| = 1.
        double m2 = DVector3.Dot(Body.L, Body.L);
        double E  = Body.Energy;

        Debug.Log(string.Format("Energy: {0} Momentum {1}", E, m2));

        // For given Lx, Ly, Lz, the energy is:
        //        Lx^2   Ly^2   Lz^2
        //  2E =  ---- + ---- +	----
        //        Ix	 Iy		Iz
        // Applying our scale, and turning this into an ellipsoid equation gives the following ellipse extents:
        Vector3 ellipsoid_scale = new Vector3((float)Math.Sqrt(E * Body.I.x * 2 / m2),
                                              (float)Math.Sqrt(E * Body.I.y * 2 / m2),
                                              (float)Math.Sqrt(E * Body.I.z * 2 / m2));

        Debug.Log(string.Format("Ellipsoid scale: {0},{1},{2}", ellipsoid_scale.x, ellipsoid_scale.y, ellipsoid_scale.z));

        // Need another factor of 2 in the final scale because a standard Unity sphere is radius .5:
        EnergyEllipsoid.transform.localScale = ellipsoid_scale * 2;

        BinetFollowL.Target = Body;
        BinetFollowL.Scale  = (float)(1 / Math.Sqrt(m2));


        BinetFollowTrail.enabled = false;
        BinetFollowTrail.Clear();
    }
Пример #18
0
        public void ComputeSurface(int ApproxLevel)
        {
            lock (locker)
            {
                double step = 1.0 / ApproxLevel;

                List <Vertex>  v = new List <Vertex>();
                List <Polygon> p = new List <Polygon>();

                for (int i = 0; i <= ApproxLevel; ++i)
                {
                    for (int j = 0; j <= ApproxLevel; ++j)
                    {
                        DVector3 vec  = At(i * step, j * step);
                        Vertex   vert = new Vertex(vec);
                        v.Add(vert);
                    }
                }

                for (int i = 0; i <= ApproxLevel - 1; ++i)
                {
                    for (int j = 0; j <= ApproxLevel - 1; ++j)
                    {
                        Polygon pol = new Polygon(new List <Vertex>()
                        {
                            v[i * (ApproxLevel + 1) + j], v[i * (ApproxLevel + 1) + j + 1], v[(i + 1) * (ApproxLevel + 1) + j + 1], v[(i + 1) * (ApproxLevel + 1) + j]
                        });
                        p.Add(pol);
                    }
                }

                vertices = v.ToArray();
                polygons = p.ToArray();
            }
        }
Пример #19
0
        /// <summary>
        /// Gets the <see cref="T:Mapbox.Utils.Vector2dBounds"/> of a tile.
        /// </summary>
        /// <param name="x"> Tile X position. </param>
        /// <param name="y"> Tile Y position. </param>
        /// <param name="zoom"> Zoom level. </param>
        /// <returns> The <see cref="T:Mapbox.Utils.Vector2dBounds"/> of the tile. </returns>
        public static DRect TileIdToBounds(int x, int z, int zoom)
        {
            DVector3 sw = new DVector3(TileYToNWLatitude(z, zoom), 0, TileXToNWLongitude(x + 1, zoom));
            DVector3 ne = new DVector3(TileYToNWLatitude(z + 1, zoom), 0, TileXToNWLongitude(x, zoom));

            return(new DRect(sw, ne));
        }
Пример #20
0
 /// <summary>
 /// Updates the position of all the GameObjects
 /// </summary>
 /// <param name="deviceLocation">Location.</param>
 void UpdatePositions(Location deviceLocation, DVector3 delta)
 {
     foreach (var entry in entries)
     {
         UpdateObjectPosition(entry.Value, deviceLocation, delta);
     }
 }
Пример #21
0
        //Returns bounds of the given tile in EPSG:900913 coordinates
        public static DRect TileBoundsInMeters(DVector3 tileindex, int zoom)
        {
            DVector3 min = PixelsToMeters(new DVector3(tileindex.x * TileSize, 0, tileindex.z * TileSize), zoom);
            DVector3 max = PixelsToMeters(new DVector3((tileindex.x + 1) * TileSize, 0, (tileindex.z + 1) * TileSize), zoom);

            return(new DRect(new DVector3(min.x, 0, min.z), new DVector3(max.x, 0, max.z)));
        }
Пример #22
0
    void UpdatePosition()
    {
        var body_l = Body.BodyL();
        var offset = body_l.normalized * 4;

        transform.localPosition = DVector3.ToUnity(offset);
        transform.LookAt(MomentumSphere.transform);
    }
Пример #23
0
 // вершины по часовой стрелке
 public Polygon(DVector4 p1, DVector4 p2, DVector4 p3)
 {
     P1     = p1;
     P2     = p2;
     P3     = p3;
     Normal = DVector3.CrossProduct(P3 - P1, P2 - P1)
              .Normalized();
 }
Пример #24
0
 public void Accept(DVector3 type, Utf8JsonWriter x)
 {
     x.WriteStartObject();
     x.WriteNumber("x", type.Value.X);
     x.WriteNumber("y", type.Value.Y);
     x.WriteNumber("z", type.Value.Z);
     x.WriteEndObject();
 }
Пример #25
0
        //Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
        public static DVector3 MetersToPixels(DVector3 m, int zoom)
        {
            var res = Resolution(zoom);
            var pix = new DVector3();

            pix.x = ((m.x + OriginShift) / res);
            pix.y = ((-m.y + OriginShift) / res);
            return(pix);
        }
Пример #26
0
        //Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
        public static DVector3 LatLonToMeters(double lat, double lon)
        {
            DVector3 p = new DVector3();

            p.x = (lon * OriginShift / 180);
            p.y = (Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180));
            p.y = (p.y * OriginShift / 180);
            return(new DVector3(p.x, 0, p.y));
        }
Пример #27
0
        //Converts pixel coordinates in given zoom level of pyramid to EPSG:900913
        public static DVector3 PixelsToMeters(DVector3 p, int zoom)
        {
            var res = Resolution(zoom);
            var met = new DVector3();

            met.x = (p.x * res - OriginShift);
            met.z = (p.z * res - OriginShift); /// removed -
            return(met);
        }
Пример #28
0
        //Converts XY point from (Spherical) Web Mercator EPSG:3785 (unofficially EPSG:900913) to lat/lon in WGS84 Datum
        public static DVector3 MetersToLatLon(DVector3 m)
        {
            DVector3 ll = new DVector3();

            ll.x = (m.x / OriginShift) * 180;
            ll.z = (m.z / OriginShift) * 180;
            ll.z = 180 / Math.PI * (2 * Math.Atan(Math.Exp(ll.z * Math.PI / 180)) - Math.PI / 2);
            return(new DVector3(ll.z, 0, ll.x));
        }
Пример #29
0
        public void GenerateWaterJSON(string data, GameObject Container, DVector3 PositionMeters)
        {
            mc = transform.parent.Find("terrain").GetComponent <MeshCollider>();
            TileBoundsMeters = this.transform.parent.GetComponent <MassiveTile>().TileBoundsMeters;
            Container.layer  = LayerMask.NameToLayer("Water");
            sData            = data;
            Data             = (Dictionary <string, object>)MiniJSON.Json.Deserialize(sData);

            IList features = (IList)Data["features"];

            foreach (IDictionary feature in features)
            {
                IDictionary geometry   = (IDictionary)feature["geometry"];
                string      type       = (string)geometry["type"];
                IDictionary properties = (IDictionary)feature["properties"];
                string      kind       = OSMTools.GetProperty(properties, "kind");

                List <List <Vector3> > segments = new List <List <Vector3> >();

                /*
                 * if (type == "LineString")
                 * {
                 * List<DVector3> list = new List<DVector3>();
                 * foreach (IList piece in (IList)geometry["coordinates"])
                 * {
                 *  double dx = (double)piece[0];
                 *  double dz = (double)piece[1];
                 *  DVector3 v = MapFuncs.LatLonToMeters((float)dz, (float)dx);
                 *  v -= PositionMeters;
                 *  list.Add(v);
                 * }
                 * segments.Add(list);
                 * }
                 */

                if (type == "MultiPolygon")
                {
                    IList segs = (IList)geometry["coordinates"];
                    foreach (IList part in segs)
                    {
                        segments = OSMTools.CreateMultiPolygon(part, PositionMeters);
                        GenerateGeometry(segments, Container, properties, type);
                    }
                }
                if (type == "Polygon")
                {
                    IList segs = (IList)geometry["coordinates"];
                    foreach (IList part in segs)
                    {
                        segments = OSMTools.CreatePolygon(part, PositionMeters.ToVector3());
                        GenerateGeometry(segments, Container, properties, type);
                    }
                }

                //Debug.Log(segments);
            }
        }
Пример #30
0
    private void DrawPolygonNormal(Polygon p, Graphics g, double Width, double Height)
    {
        DVector3 center = PolygonCenter(p);

        double amp = 40.0 * WindowScale;

        g.DrawLine(Pens.AliceBlue, (float)(center.X + Width * 0.5 + ShiftX), (float)(center.Y + Height * 0.5 - ShiftY),
                   (float)(center.X + p.Normal.X * amp + Width * 0.5 + ShiftX), (float)(center.Y + p.Normal.Y * amp + Height * 0.5 - ShiftY));
    }
Пример #31
0
 private void Awake()
 {
     _transforms  = new List <WorldTransform>();
     _sceneOrigin = new DVector3(
         _sceneOriginStartX,
         _sceneOriginStartY,
         _sceneOriginStartZ);
     _region = WorldPointToRegion(_sceneOrigin);
 }
Пример #32
0
        public static void DrawAABB(DVector3 Max, DVector3 Min, Vector3 color)
        {
            LineList.Add(new DebugLine(new DVector3(Max.X, Max.Y, Max.Z), new DVector3(Max.X, Max.Y, Min.Z), color));
            LineList.Add(new DebugLine(new DVector3(Max.X, Max.Y, Min.Z), new DVector3(Min.X, Max.Y, Min.Z), color));
            LineList.Add(new DebugLine(new DVector3(Min.X, Max.Y, Min.Z), new DVector3(Min.X, Max.Y, Max.Z), color));
            LineList.Add(new DebugLine(new DVector3(Min.X, Max.Y, Max.Z), new DVector3(Max.X, Max.Y, Max.Z), color));

            LineList.Add(new DebugLine(new DVector3(Max.X, Min.Y, Max.Z), new DVector3(Max.X, Min.Y, Min.Z), color));
            LineList.Add(new DebugLine(new DVector3(Max.X, Min.Y, Min.Z), new DVector3(Min.X, Min.Y, Min.Z), color));
            LineList.Add(new DebugLine(new DVector3(Min.X, Min.Y, Min.Z), new DVector3(Min.X, Min.Y, Max.Z), color));
            LineList.Add(new DebugLine(new DVector3(Min.X, Min.Y, Max.Z), new DVector3(Max.X, Min.Y, Max.Z), color));

            LineList.Add(new DebugLine(new DVector3(Max.X, Max.Y, Max.Z), new DVector3(Max.X, Min.Y, Max.Z), color));
            LineList.Add(new DebugLine(new DVector3(Max.X, Max.Y, Min.Z), new DVector3(Max.X, Min.Y, Min.Z), color));
            LineList.Add(new DebugLine(new DVector3(Min.X, Max.Y, Min.Z), new DVector3(Min.X, Min.Y, Min.Z), color));
            LineList.Add(new DebugLine(new DVector3(Min.X, Max.Y, Max.Z), new DVector3(Min.X, Min.Y, Max.Z), color));
        }
Пример #33
0
        public TestSprite(Device device, DVector3 Position)
        {
            this.Position = Position;
            MMesh = ContentManager.LoadMesh("Content/Models/BaseSprite.mesh");
            EEEM = ContentManager.LoadEffect("Content/Shaders/BaseSprite");
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
Пример #34
0
        public GSSprite(Device device, DVector3 Position)
        {
            //float3 Position //12
            //half2 Size //16
            //half4 AABBTexCoord //24
            //half4 AditiveColor //32
            InputElement[] elements = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0),
                new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0),
                new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0),
            };

            BytesPerVertex = 32;
            VertexsCount = 1;

            var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true);

            vertices.Write(Conversion.ToVector3(Position));
            vertices.Write(new Half2(10, 10));
            vertices.Write(new Half4(0, 0, 1, 1));
            vertices.Write(new Half4(1, 0, 0, 1));
            vertices.Position = 0;

            Vertexs = new Buffer(device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
            vertices.Dispose();

            this.Position = Position;
            EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements);
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
Пример #35
0
        public static int OcclusionRequest(DVector3 Position)
        {
            if (LastFreeIndex >= OcclusionRequestPosition.Length)
                System.Array.Resize(ref OcclusionRequestPosition, OcclusionRequestPosition.Length * 2);

            OcclusionRequestPosition[LastFreeIndex] = Position;
            LastFreeIndex++;

            if (LastFreeIndex > OcclSRV.Length * OcclPixelInTex)
            {
                //Resize
                int newsize = OcclSRV.Length * 2;
                System.Array.Resize(ref OcclTexture, newsize);
                System.Array.Resize(ref OcclSRV, newsize);
                System.Array.Resize(ref OcclRTV, newsize);

                for (int i = 0; i < newsize; i++)
                    if (OcclTexture[i] == null)
                        InitOcclInd(i);
            }
            return LastFreeIndex - 1;
        }
Пример #36
0
        public static void DrawLens(DVector3 Position, Vector2 Size, Vector2 UVMin, Vector2 UVMax, Vector4 Color, TextureContainer Textur)
        {
            if (Textur == null) return;
            if (LastFreeIndex >= MassSize)
            {
                //resize
                MassSize = Utils.GetBinResize(LastFreeIndex + 1);
                System.Array.Resize(ref MasterRequest, MassSize);
                System.Array.Resize(ref SlaveRequest, MassSize);

                for (int i = LastFreeIndex; i < MassSize; i++)
                {
                    MasterRequest[i] = new Request();
                    SlaveRequest[i] = new Request();
                    ResizeVertex = true;
                }
            }

            MasterRequest[LastFreeIndex].Position = Position;
            MasterRequest[LastFreeIndex].Size = Size;
            MasterRequest[LastFreeIndex].UVMin = UVMin;
            MasterRequest[LastFreeIndex].UVMax = UVMax;
            MasterRequest[LastFreeIndex].Color = Color;
            MasterRequest[LastFreeIndex].Textur = Textur;

            LastFreeIndex++;
        }
 public EELightShadow(DVector3 Position, Vector3 Color)
 {
     this.Position = Position;
     this.Color = Color;
     SCamera = new EEShadowCamera(1f, 1000f);
 }
Пример #38
0
        public static void RenderAllSplits(Device device, EEDCamera Camera, DVector3 ShadowVector, KDtree KDT, List<GameObject> ObjInCam)
        {
            for (int t = 0; t < ObjInCam.Count; t++)
                if (ObjInCam[t] != null)
                {
                    ObjInCam[t].StartSplit = -1;
                    ObjInCam[t].StopSplit = -1;
                }
            //string title = "";
            GenerateSplit(Camera, ShadowVector);
            for (int i = 0; i < SplitsNumber; i++)
            {
                DMatrix Inv = DMatrix.Invert(Conversion.ToDoubleMatrix(LightViewProjMatrix * CropMatrices[i]));
                Vector3 View = Conversion.ToVector3(DVector3.Transform(new DVector3(0, 0, 1), Inv) - DVector3.Transform(new DVector3(0, 0, 0), Inv));
                Vector3 Right = Conversion.ToVector3(DVector3.Transform(new DVector3(1, 0, 0), Inv) - DVector3.Transform(new DVector3(0, 0, 0), Inv));
                Vector3 Up = Conversion.ToVector3(DVector3.Transform(new DVector3(0, 1, 0), Inv) - DVector3.Transform(new DVector3(0, 0, 0), Inv));
                BoundingFrustum BF = new BoundingFrustum(View, Right, Up);

                ObjInSplites[i] =

                    //KDT.GetBody(new DVector3(), ShadowDistance);
                    KDT.GetBodyInCamera(NewCamPositions[i], BF);

                //title += "  "  + ObjInSplites[i].Count;
            }
            //Program.form.Text = title;
            RenderTargetView RTV_ = null;
            device.ImmediateContext.OutputMerger.SetTargets(SMArrayDSV, RTV_);

            device.ImmediateContext.ClearDepthStencilView(SMArrayDSV, DepthStencilClearFlags.Depth, 1.0f, 0);

            device.ImmediateContext.Rasterizer.SetViewports(SMArrayV);

            for (int i = 0; i < SplitsNumber; i++)
            {
                for (int y = 0; y < ObjInSplites[i].Count; y++)
                {
                    GameObject GO = ObjInSplites[i][y];
                    if (GO != null)
                    {
                        int Start = i;
                        int Stop = i;

                        if (i < SplitsNumber)
                        {
                            for (int j = i + 1; j < SplitsNumber; j++)
                            {
                                //Перебор последующих срезов
                                if (ObjInSplites[j].Contains(GO))
                                {
                                    Stop = j;
                                    ObjInSplites[j].Remove(GO);
                                }
                            }
                        }
                        //Draw
                        GO.StartSplit = Start;
                        GO.StopSplit = Stop;

                        GO.DrawPSSMSplit(device, NewShadowPos, LightViewProjMatrix, CropMatrices, Start, Stop);
                    }
                }
            }
        }
Пример #39
0
        private static void GenerateSplit(EEDCamera Camera, DVector3 ShadowVector)
        {
            Vector3 Up = new Vector3(0, 1, 0);
            NewShadowPos = Camera.position;
            DVector3.Normalize(ShadowVector);
            float d = Vector3.Dot(ShadowVector, Up);
            if (d == 1 || d == -1)
            {
                Up = new Vector3(1, 0, 0);
            }
            NewShadowPos -= ShadowDistance * ShadowVector;

            const int ShadowStep = 50;
            NewShadowPos.X = ((int)NewShadowPos.X) / ShadowStep * ShadowStep;
            NewShadowPos.Y = ((int)NewShadowPos.Y) / ShadowStep * ShadowStep;
            NewShadowPos.Z = ((int)NewShadowPos.Z) / ShadowStep * ShadowStep;

            double Coff = 0.125f;
            for (int i = 0; i < SplitsNumber + 1; i++)
            {
                SplitSlices[i] = (Camera.nearClip + (Camera.farClip - Camera.nearClip) * (float)i / (float)SplitsNumber) * (Coff);
                SplitSlices[i] += (Camera.nearClip * System.Math.Pow(Camera.farClip / Camera.nearClip, (float)i / (float)SplitsNumber)) * (1 - Coff);
                SplitSlices[i] /= Camera.farClip;
                SplitSlices[i] *= ShadowDistance;

                CamFrustumPos[i, 0] = Camera.position + (Camera.FarT1 - Camera.position) * (SplitSlices[i] / Camera.farClip);
                CamFrustumPos[i, 1] = Camera.position + (Camera.FarT2 - Camera.position) * (SplitSlices[i] / Camera.farClip);
                CamFrustumPos[i, 2] = Camera.position + (Camera.FarT3 - Camera.position) * (SplitSlices[i] / Camera.farClip);
                CamFrustumPos[i, 3] = Camera.position + (Camera.FarT4 - Camera.position) * (SplitSlices[i] / Camera.farClip);
            }

            Matrix ProjShadowMatrix = Matrix.OrthoRH(100f, 100f, (float)ShadowDistance / 1000f, (float)ShadowDistance * 2f);
            Matrix ViewShadowMatrix = Matrix.LookAtRH(new Vector3(0, 0, 0), Conversion.ToVector3(ShadowVector), Vector3.Cross(Camera.direction, ShadowVector));
            LightViewProjMatrix = ViewShadowMatrix * ProjShadowMatrix;

            for (int i = 0; i < SplitsNumber; i++)
            {

                Vector3[] TransformSplit = new Vector3[8];
                for (int t = 0; t < 4; t++)
                {
                    TransformSplit[t] = Conversion.ToVector3(Vector3.Transform(Conversion.ToVector3(CamFrustumPos[i, t] - NewShadowPos), LightViewProjMatrix));
                    TransformSplit[t + 4] = Conversion.ToVector3(Vector3.Transform(Conversion.ToVector3(CamFrustumPos[i + 1, t] - NewShadowPos), LightViewProjMatrix));
                }

                Vector3 AABBMax = TransformSplit[0];
                Vector3 AABBMin = TransformSplit[0];

                for (int y = 0; y < 8; y++)
                {
                    if (AABBMax.X < TransformSplit[y].X) AABBMax.X = TransformSplit[y].X;
                    if (AABBMax.Y < TransformSplit[y].Y) AABBMax.Y = TransformSplit[y].Y;
                    if (AABBMax.Z < TransformSplit[y].Z) AABBMax.Z = TransformSplit[y].Z;

                    if (AABBMin.X > TransformSplit[y].X) AABBMin.X = TransformSplit[y].X;
                    if (AABBMin.Y > TransformSplit[y].Y) AABBMin.Y = TransformSplit[y].Y;
                    if (AABBMin.Z > TransformSplit[y].Z) AABBMin.Z = TransformSplit[y].Z;
                }
                /*
                AABBMax += new Vector3(0.05f);
                AABBMin -= new Vector3(0.05f);
                */

                // Create the crop matrix
                float scaleX, scaleY, scaleZ;
                float offsetX, offsetY, offsetZ;
                // Use default near-plane value
                AABBMin.Z = 0.0f;

                scaleX = 2.0f / (AABBMax.X - AABBMin.X);
                scaleY = 2.0f / (AABBMax.Y - AABBMin.Y);
                offsetX = -0.5f * (AABBMax.X + AABBMin.X) * scaleX;
                offsetY = -0.5f * (AABBMax.Y + AABBMin.Y) * scaleY;
                scaleZ = 1.0f / ((AABBMax.Z - AABBMin.Z));
                offsetZ = -AABBMin.Z * scaleZ;

                const int CoffShadowStep = 5;
                const float CoffMulti = 100f;
                const float CoffMultiScale = 1000f;

                offsetX = ((float)(((int)(offsetX * CoffMulti)) / CoffShadowStep * CoffShadowStep)) / CoffMulti;
                offsetY = ((float)(((int)(offsetY * CoffMulti)) / CoffShadowStep * CoffShadowStep)) / CoffMulti;
                offsetZ = ((float)(((int)(offsetZ * CoffMulti)) / CoffShadowStep * CoffShadowStep)) / CoffMulti;

                scaleX = ((float)(((int)(scaleX * CoffMultiScale)) / CoffShadowStep * CoffShadowStep)) / CoffMultiScale;
                scaleY = ((float)(((int)(scaleY * CoffMultiScale)) / CoffShadowStep * CoffShadowStep)) / CoffMultiScale;
                scaleZ = ((float)(((int)(scaleZ * CoffMultiScale)) / CoffShadowStep * CoffShadowStep)) / CoffMultiScale;

                CropMatrices[i] = new Matrix(scaleX, 0.0f, 0.0f, 0.0f, 0.0f, scaleY, 0.0f, 0.0f, 0.0f, 0.0f, scaleZ, 0.0f, offsetX, offsetY, offsetZ, 1.0f);

                DMatrix Inv = DMatrix.Invert(Conversion.ToDoubleMatrix(LightViewProjMatrix * CropMatrices[i]));

                DVector3 LocPos = DVector3.Transform(new DVector3(), Inv);
                NewCamPositions[i] = NewShadowPos + LocPos;
            }
        }
Пример #40
0
 public static void DrawLocator(DVector3 Pos, double Size, Vector3 color)
 {
     LineList.Add(new DebugLine(new DVector3(Pos.X - Size, Pos.Y, Pos.Z), new DVector3(Pos.X + Size, Pos.Y, Pos.Z), color));
     LineList.Add(new DebugLine(new DVector3(Pos.X, Pos.Y - Size, Pos.Z), new DVector3(Pos.X, Pos.Y + Size, Pos.Z), color));
     LineList.Add(new DebugLine(new DVector3(Pos.X, Pos.Y, Pos.Z - Size), new DVector3(Pos.X, Pos.Y, Pos.Z + Size), color));
 }
Пример #41
0
 /// <summary>
 /// Adds the specified vector3 to me.
 /// </summary>
 /// <param name="vector3">The vector3.</param>
 public void Add(DVector3 vector3)
 {
     this = this + vector3;
 }
Пример #42
0
 /// <summary>
 /// Divides the specified vector3 to me.
 /// </summary>
 /// <param name="vector3">The vector3.</param>
 public void Divide(DVector3 vector3)
 {
     this = this / vector3;
 }
Пример #43
0
 /// <summary>
 /// Multiplies the specified vector3 with me.
 /// </summary>
 /// <param name="vector3">The vector3.</param>
 public void Multiply(DVector3 vector3)
 {
     this = this * vector3;
 }