Пример #1
0
	static void Main ()
	{
		V2 a = new V2 ();
		V3 b = new V3 ();

		V2 s = a - b;
	}
        public virtual Color Compute(
            List<Light> lights, Object3D obj, V3 p, V2 uv
        )
        {
            Color illumination = new Color(0, 0, 0);

            foreach (Light l in lights) {
                if (l.GetType().Name == "AmbientLight") {
                    illumination += ComputeAmbientLight(
                        (AmbientLight) l, obj, p, uv
                    );
                }
                else if (l.GetType().Name == "PointLight") {
                    illumination += ComputePointLight(
                        (PointLight) l, obj, p, uv
                    );
                }
                else if (l.GetType().Name == "DirectionalLight") {
                    illumination += ComputeDirectionalLight(
                        (DirectionalLight) l, obj, p, uv
                    );
                }
            }

            return illumination;
        }
        /// Computes the diffuse and specular components of the Phong
        /// reflection model for a directional light.
        public override Color ComputeDirectionalLight(
            DirectionalLight dL, Object3D obj, V3 p, V2 uv
        )
        {
            V3 incidentVec = -dL.Direction;

            return ComputeDiffuseSpecular(dL, obj, p, uv, incidentVec);
        }
        /// Returns the texture color at coordinates (u,v). If no Texture has
        /// been given for this Object3D, return the object's Color property.
        public Color TextureColor(V2 uv)
        {
            if (Material.Texture != null) {
                return Material.Texture.Color(uv);
            }

            return Material.Color;
        }
        /// Returns the altered normal if this object possesses a bump map, or
        /// the unaltered one if it does not.
        public V3 Normal(V3 p, V2 uv)
        {
            if (Material.BumpMap != null) {
                return AlteredNormal(p, uv);
            }

            return Normal(p);
        }
        /// Computes the diffuse and specular components of the Phong
        /// reflection model for a point light.
        public override Color ComputePointLight(
            PointLight pL, Object3D obj, V3 p, V2 uv
        )
        {
            V3 incidentVec = pL.Position - p;
            incidentVec.Normalize();

            return ComputeDiffuseSpecular(pL, obj, p, uv, incidentVec);
        }
        public override Tuple<V3, V3> DerivativePoint(V2 uv)
        {
            V3 dPdu = new V3(VA);
            dPdu.Normalize();

            V3 dPdv = new V3(VB);
            dPdv.Normalize();

            return new Tuple<V3,V3>(dPdu, dPdv);
        }
Пример #8
0
        public V2 CalculatePosition(WorldSpaceCell cell)
        {
            var pos = new V2(
                cell.X * TileStepX + (cell.Y % 2 == 1 ? OddRowXOffset : 0),
                cell.Y * TileStepY + (HeightTileOffset * cell.Z));

            System.Diagnostics.Debug.WriteLine(pos.X + ", " + pos.Y);

            return pos;
        }
 public Texture(string textureFile, V2 tileUV) {
     Bitmap bmp = Open(textureFile);
     
     Width = bmp.Width;
     Height = bmp.Height;
     
     FillColors(bmp);
     
     bmp.Dispose();
     
     TileUV = tileUV;
 }
Пример #10
0
        /// <summary>
        /// Scales the renderinfo with respect to width/height ratio.
        /// Only one side will fit the given Dimension exactly afterwards.
        /// </summary>
        /// <param name="Dimension"></param>
        /// <param name="CenterHorizontal"></param>
        /// <param name="CenterVertical"></param>
        protected void ScaleToBox(V2 Dimension, bool CenterHorizontal = false, bool CenterVertical = false)
        {
            // get scales for both axis
            Real hScale = Dimension.X / this.Dimension.X;
            Real vScale = Dimension.Y / this.Dimension.Y;

            // use the smaller factor so the other side "still fits"
            // into given dimension
            if (hScale >= vScale)
            {
                // apply scale from y-side
                Scale(vScale);

                if (CenterHorizontal)
                {
                    Real stride      = (Dimension.X - this.Dimension.X) / 2.0f;
                    Real strideratio = stride / Dimension.X;

                    Translate(new V2(stride, 0.0f));

                    uvstart.X = 0.0f + strideratio;
                    uvend.X   = 1.0f - strideratio;
                }
                else
                {
                    // adjust UVEnd on x-side
                    uvend.X = 1.0f * (this.Dimension.X / Dimension.X);
                }
            }
            else
            {
                // apply scale from x-side
                Scale(hScale);

                if (CenterVertical)
                {
                    Real stride      = (Dimension.Y - this.Dimension.Y) / 2.0f;
                    Real strideratio = stride / Dimension.Y;

                    Translate(new V2(0.0f, stride));

                    uvstart.Y = 0.0f + strideratio;
                    uvend.Y   = 1.0f - strideratio;
                }
                else
                {
                    // adjust UVEnd on y-side
                    uvend.Y = 1.0f * (this.Dimension.Y / Dimension.Y);
                }
            }

            this.Dimension = Dimension;
        }
Пример #11
0
        public void Constructor()
        {
            var a = new V2();

            Assert.Zero(a.X);
            Assert.Zero(a.Y);

            var b = new V2(1.1f, 2.2f);

            Assert.AreEqual(1.1f, b.X);
            Assert.AreEqual(2.2f, b.Y);
        }
Пример #12
0
        override public Tuple <V3, V3> DerivativePoint(V2 uv)
        {
            V3 dPdu = new V3(VA);

            dPdu.Normalize();

            V3 dPdv = new V3(VB);

            dPdv.Normalize();

            return(new Tuple <V3, V3>(dPdu, dPdv));
        }
Пример #13
0
        private static List <V2> GenerateCoordinates(IEnumerable <V2> directions, V2 origin)
        {
            var coords     = new List <V2>();
            var currOrigin = origin.Clone();

            foreach (var dir in directions)
            {
                currOrigin += dir;
                coords.Add(currOrigin.Clone());
            }
            return(coords);
        }
    private void PickNewTarget()
    {
        float   magnitude  = Random.value * this.maxRadiusFromCenter;
        float   angle      = Random.value * Mathf.PI * 2f;
        Vector2 nextTarget = V2.FromMagnitudeAngle(magnitude, angle);

        this.vectorFromStartToTarget = nextTarget - this.currentTarget;
        this.currentTarget           = nextTarget;
        this.progressToTarget        = 0;
        this.stopMovingTime          = Time.time + this.driftInterval - this.stayAtTargetDuration;
        this.nextDriftTime           = Time.time + this.driftInterval;
    }
        private Color ComputeDiffuse(
            Light l, V3 incidentVec, V3 normalVec, Object3D obj, V2 uv
        )
        {
            Color diffuseIllu = new Color(0, 0, 0);
            if (incidentVec * normalVec > 0.0f) {
                diffuseIllu = obj.TextureColor(uv) * l.Intensity *
                              obj.Material.KDiffuse * (incidentVec * normalVec);
            }

            return diffuseIllu;
        }
Пример #16
0
            public RenderInfo(int Size)
            {
                this.P      = new V3[Size];
                this.UV     = new V2[Size];
                this.Normal = new V3(0.0f, 0.0f, 0.0f);

                for (int i = 0; i < Size; i++)
                {
                    P[i]  = new V3(0.0f, 0.0f, 0.0f);
                    UV[i] = new V2(0.0f, 0.0f);
                }
            }
Пример #17
0
        public Texture(string textureFile, V2 tileUV)
        {
            Bitmap bmp = Open(textureFile);

            Width  = bmp.Width;
            Height = bmp.Height;

            FillColors(bmp);

            bmp.Dispose();

            TileUV = tileUV;
        }
Пример #18
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (this.moved)
        {
            // Move this enemy.
            Vector2 newPosition = V2.FromV3(this.transform.position) + this.currentMovement;
            this.rb.MovePosition(newPosition);

            // Reset variables for next frame.
            this.currentMovement = Vector2.zero;
            this.moved           = false;
        }
    }
Пример #19
0
    void DrawArrow(V2 from, V2 to, float w, Color color)
    {
        V2    dp    = to - from;
        float dpLen = dp.Len();
        V2    dir   = dp / dpLen;
        V2    perp  = new V2 {
            x = dir.y, y = -dir.x
        };
        V2 cornerHorDp = perp * w;

        const float HEAD_LEN_RATIO = 0.3f;

        V2 corner00      = from + cornerHorDp;
        V2 corner01      = from - cornerHorDp;
        V2 corner1Center = from + (dp * (1f - HEAD_LEN_RATIO));
        V2 corner10      = corner1Center + cornerHorDp;
        V2 corner11      = corner1Center - cornerHorDp;

        const float HEAD_WITH_RATIO = 2f;

        V2 headTop     = to;
        V2 headBottom0 = corner1Center + cornerHorDp * HEAD_WITH_RATIO;
        V2 headBottom1 = corner1Center - cornerHorDp * HEAD_WITH_RATIO;

        renderVerts.Add(Convert(corner00));
        renderVerts.Add(Convert(corner01));
        renderVerts.Add(Convert(corner10));
        renderVerts.Add(Convert(corner11));
        renderVerts.Add(Convert(headTop));
        renderVerts.Add(Convert(headBottom0));
        renderVerts.Add(Convert(headBottom1));

        int atVert = renderVerts.Count - 1;

        renderTris.Add(atVert--);
        renderTris.Add(atVert--);
        renderTris.Add(atVert--);

        renderTris.Add(atVert);
        renderTris.Add(atVert - 1);
        renderTris.Add(atVert - 2);

        renderTris.Add(atVert - 1);
        renderTris.Add(atVert - 2);
        renderTris.Add(atVert - 3);

        for (int i = 0; i < 7; i++)
        {
            renderColors.Add(color);
        }
    }
        public void TestEchoTasksAutoRegisterType()
        {
            var v1 = _grid1.GetCompute().ExecuteJavaTask <V1>(ComputeApiTest.EchoTask, EchoTypeV1Action);

            Assert.AreEqual("V1", v1.Name);

            var arg = new V2 {
                Name = "V2"
            };

            var v2 = _grid1.GetCompute().ExecuteJavaTask <V2>(ComputeApiTest.EchoArgTask, arg);

            Assert.AreEqual(arg.Name, v2.Name);
        }
Пример #21
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(BasisSurface != null ? BasisSurface.ToStepValue() : "$");
            parameters.Add(U1 != null ? U1.ToStepValue() : "$");
            parameters.Add(V1 != null ? V1.ToStepValue() : "$");
            parameters.Add(U2 != null ? U2.ToStepValue() : "$");
            parameters.Add(V2 != null ? V2.ToStepValue() : "$");
            parameters.Add(Usense != null ? Usense.ToStepValue() : "$");
            parameters.Add(Vsense != null ? Vsense.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
Пример #22
0
        public void Scale()
        {
            V2 expected;
            V2 returned;

            // --- TEST ---

            expected = new V2(0.0f, 0.0f);
            returned = new V2(0.0f, 0.0f);
            returned.Scale(10f);

            Assert.AreEqual(expected.X, returned.X, EPSILON);
            Assert.AreEqual(expected.Y, returned.Y, EPSILON);

            // --- TEST ---

            expected = new V2(10.0f, 0.0f);
            returned = new V2(1.0f, 0.0f);
            returned.Scale(10f);

            Assert.AreEqual(expected.X, returned.X, EPSILON);
            Assert.AreEqual(expected.Y, returned.Y, EPSILON);

            // --- TEST ---

            expected = new V2(0.0f, -10.0f);
            returned = new V2(0.0f, -1.0f);
            returned.Scale(10f);

            Assert.AreEqual(expected.X, returned.X, EPSILON);
            Assert.AreEqual(expected.Y, returned.Y, EPSILON);

            // --- TEST ---

            expected = new V2(0.0f, 0.0f);
            returned = new V2(1.34f, -5.563f);
            returned.Scale(0.0f);

            Assert.AreEqual(expected.X, returned.X, EPSILON);
            Assert.AreEqual(expected.Y, returned.Y, EPSILON);

            // --- TEST ---

            expected = new V2(EPSILON, EPSILON);
            returned = new V2(1.0f, 1.0f);
            returned.Scale(EPSILON);

            Assert.AreEqual(expected.X, returned.X, EPSILON);
            Assert.AreEqual(expected.Y, returned.Y, EPSILON);
        }
Пример #23
0
        /// <summary>
        /// Recalculates the ViewerAngle property based on a viewer's position.
        /// </summary>
        /// <param name="ViewerPosition"></param>
        public void UpdateViewerAngle(V2 ViewerPosition)
        {
            V2 direction = TargetObject.Position2D - Position2D;

            direction.Normalize();

            ushort angle = MathUtil.GetAngleForDirection(direction);

            // update viewer angle
            ViewerAngle = MathUtil.GetAngle(ViewerPosition, Position2D, angle);

            // mark for possible appearance change
            appearanceChanged = true;
        }
Пример #24
0
    void OnSceneGUI()
    {
        // input
        Event   e   = Event.current;
        Vector2 pos = model.TfInvPnt(HandleUtility.GUIPointToWorldRay(e.mousePosition).origin);

        // select index segment
        int selIdx = -1, selSeg = -1;

        for (int i = 0; i < model.points.Count; i++)
        {
            if (V3.Dis(model.points[i], pos) < 0.1f)
            {
                selIdx = i;
            }
            if (i == 0 && HandleUtility.DistancePointLine(pos, model.points[i], V2.X(model.points[i], 0)) < 0.1f)
            {
                selSeg = 0;
            }
            if (i >= 1 && HandleUtility.DistancePointLine(pos, model.points[i - 1], model.points[i]) < 0.1f)
            {
                selSeg = i;
            }
        }

        // add point
        if (e.type == EventType.MouseDown && e.button == 0 && e.shift)
        {
            model.points.Insert(selSeg >= 0 ? selSeg : model.points.Count, pos);
        }

        // delete point
        if (e.type == EventType.MouseDown && e.button == 1 && selIdx >= 0)
        {
            model.points.RemoveAt(selIdx);
        }

        // draw
        Handles.color = Col.red;
        for (int i = 0; i < model.points.Count; i++)
        {
            model.points[i] = model.TfInvPnt(
                Handles.FreeMoveHandle(
                    model.TfInvPnt(model.points[i]),
                    Q.O, 0.1f, V3.O, Handles.CylinderHandleCap
                    )
                );
        }
        model.UpdateMesh();
    }
Пример #25
0
        public void IEquatableImpl()
        {
            var a  = new V2(1, 2);
            var b  = new V2(1, 2);
            var c  = new V2(1, 3);
            var d  = new V2(2, 2);
            var ec = EqualityComparer <V2> .Default;

            Assert.True(ec.Equals(a, b));
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
            Assert.False(ec.Equals(a, c));
            Assert.False(ec.Equals(a, d));
            Assert.False(ec.Equals(c, d));
        }
Пример #26
0
        private Color ComputeDiffuse(
            Light l, V3 incidentVec, V3 normalVec, Object3D obj, V2 uv
            )
        {
            Color diffuseIllu = new Color(0, 0, 0);

            if (incidentVec * normalVec > 0.0f)
            {
                diffuseIllu = obj.TextureColor(uv) * l.Intensity *
                              obj.Material.KDiffuse * (incidentVec * normalVec);
            }

            return(diffuseIllu);
        }
Пример #27
0
    static Col ColDetectOneSide(List <V2> edges, List <V2> verts)
    {
        for (int i = 0, lastIndex = edges.Count - 1; i < edges.Count; lastIndex = i, i++)
        {
            V2 edgeCornerA = edges[lastIndex];
            V2 edgeCornerB = edges[i];

            V2 normal = (edgeCornerB - edgeCornerA).GetNormalized().GetPerped();

            float edgesMin = edges[0] * normal;
            float edgesMax = edgesMin;
            for (int j = 1; j < edges.Count; j++)
            {
                float p = edges[j] * normal;
                if (p < edgesMin)
                {
                    edgesMin = p;
                }
                if (edgesMax < p)
                {
                    edgesMax = p;
                }
            }

            float vertsMin = verts[0] * normal;
            float vertsMax = vertsMin;
            for (int j = 1; j < verts.Count; j++)
            {
                float p = verts[j] * normal;
                if (p < vertsMin)
                {
                    vertsMin = p;
                }
                if (vertsMax < p)
                {
                    vertsMax = p;
                }
            }

            if (edgesMax < vertsMin)
            {
                return(null);
            }
            if (vertsMax < edgesMin)
            {
                return(null);
            }
        }
        return(new Col());
    }
Пример #28
0
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            SectorNum = BitConverter.ToUInt16(Buffer, cursor);
            cursor   += TypeSizes.SHORT;

            ushort len = BitConverter.ToUInt16(Buffer, cursor);

            cursor += TypeSizes.SHORT;

            Vertices = new Polygon();

            if (RooVersion < RooFile.VERSIONFLOATCOORDS)
            {
                for (int i = 0; i < len; i++)
                {
                    int x = BitConverter.ToInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    int y = BitConverter.ToInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    Vertices.Add(new V2(x, y));
                }
            }
            else
            {
                for (int i = 0; i < len; i++)
                {
                    float x = BitConverter.ToSingle(Buffer, cursor);
                    cursor += TypeSizes.FLOAT;

                    float y = BitConverter.ToSingle(Buffer, cursor);
                    cursor += TypeSizes.FLOAT;

                    Vertices.Add(new V2(x, y));
                }
            }

            FloorP    = new V3[Vertices.Count];
            FloorUV   = new V2[Vertices.Count];
            CeilingP  = new V3[Vertices.Count];
            CeilingUV = new V2[Vertices.Count];

            return(cursor - StartIndex);
        }
Пример #29
0
 public bool EsIgual(LineSLT Valor)
 {
     if (V1.EsIgual(Valor.V1) && V2.EsIgual(Valor.V2))
     {
         return(true);
     }
     else if (V2.EsIgual(Valor.V1) && V1.EsIgual(Valor.V2))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 /// Returns the partial derivative of h (the heightmap) with respect to
 /// u and v.
 public V2 Bump(V2 uv) {
     float x = uv.U * Height;
     float y = uv.V * Width;
     
     float vv = Interpolate(x, y).GreyLevel();
     float vx = Interpolate(x + 1, y).GreyLevel();
     float vy = Interpolate(x, y + 1).GreyLevel();
     
     V2 dh = new V2(
         u: vx - vv,
         v: vy - vv
     );
     
     return dh;
 }
Пример #31
0
            public RenderInfo()
            {
                P0 = new V3(0.0f, 0.0f, 0.0f);
                P3 = new V3(0.0f, 0.0f, 0.0f);
                P1 = new V3(0.0f, 0.0f, 0.0f);
                P2 = new V3(0.0f, 0.0f, 0.0f);

                // defaults
                UV0 = new V2(0.0f, 0.0f);
                UV1 = new V2(0.0f, 1.0f);
                UV3 = new V2(1.0f, 0.0f);
                UV2 = new V2(1.0f, 1.0f);

                Normal = new V3(0.0f, 0.0f, 0.0f);
            }
Пример #32
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Player player = Player.Get();

        if (!player)
        {
            return;
        }
        Vector2 playerPosition   = Player.Get().transform.position;
        Vector2 ourPosition      = this.gun.transform.position;
        float   angleToPlayerDeg = V2.AngleTo(ourPosition, playerPosition) * Mathf.Rad2Deg;
        float   maxTurnDeg       = rateOfTurnDeg * Time.deltaTime;

        this.gun.TurnToAngleDeg(angleToPlayerDeg, maxTurnDeg);
    }
 // Use this for initialization
 void Start()
 {
     if (BuyCarScript.V01A == 0)
     {
         BuyCarScript.V01A = 2;
     }
     if (BuyCarScript.V01A == 2)
     {
         V1.SetActive(true);
     }
     if (BuyCarScript.V02A == 2)
     {
         V2.SetActive(true);
     }
     if (BuyCarScript.V03A == 2)
     {
         V3.SetActive(true);
     }
     if (BuyCarScript.V04A == 2)
     {
         V4.SetActive(true);
     }
     if (BuyCarScript.V05A == 2)
     {
         V5.SetActive(true);
     }
     if (BuyCarScript.V06A == 2)
     {
         V6.SetActive(true);
     }
     if (BuyCarScript.V07A == 2)
     {
         V7.SetActive(true);
     }
     if (BuyCarScript.V08A == 2)
     {
         V8.SetActive(true);
     }
     if (BuyCarScript.V09A == 2)
     {
         V9.SetActive(true);
     }
     if (BuyCarScript.V10A == 2)
     {
         V10.SetActive(true);
     }
     car = true;
 }
Пример #34
0
        public override object Clone()
        {
            Vertex2D v1 = (Vertex2D)V1.Clone();
            Vertex2D v2 = (Vertex2D)V2.Clone();
            Vertex2D v3 = (Vertex2D)V3.Clone();

            Triangle2D tr = new Triangle2D(v1, v2, v3);

            tr.extID = extID;

            tr.E1 = (Edge2D)E1.Clone();
            tr.E2 = (Edge2D)E2.Clone();
            tr.E3 = (Edge2D)E3.Clone();

            return(tr);
        }
Пример #35
0
        /// Returns the partial derivative of h (the heightmap) with respect to
        /// u and v.
        public V2 Bump(V2 uv)
        {
            float x = uv.U * Height;
            float y = uv.V * Width;

            float vv = Interpolate(x, y).GreyLevel();
            float vx = Interpolate(x + 1, y).GreyLevel();
            float vy = Interpolate(x, y + 1).GreyLevel();

            V2 dh = new V2(
                u: vx - vv,
                v: vy - vv
                );

            return(dh);
        }
Пример #36
0
        /// <summary>
        /// Send love to screen
        /// </summary>
        public void Fly()
        {
            _sub.SpriteBatch.Begin();

            var firstSquare = new V2(_sub.Camera.Location.X / _loader.TileStepX, _sub.Camera.Location.Y / _loader.TileStepY);
            int firstX = (int)firstSquare.X;
            int firstY = (int)firstSquare.Y;

            var squareOffset = new V2(_sub.Camera.Location.X % _loader.TileStepX, _sub.Camera.Location.Y % _loader.TileStepY);
            int offsetX = (int)squareOffset.X;
            int offsetY = (int)squareOffset.Y;

            _tileRenderer.Render(_sub.SpriteBatch, new V2(0f, 0f));

            _sub.SpriteBatch.End();
        }
Пример #37
0
        private static List <LineSegment> GenerateSegments(IEnumerable <V2> directions, V2 origin)
        {
            var segs       = new List <LineSegment>();
            V2  currOrigin = origin.Clone();

            foreach (var dir in directions)
            {
                //< Generate the segment
                var A = currOrigin.Clone();
                var B = currOrigin + dir;
                segs.Add(new LineSegment(A, B));
                //< Move the origin to the final point
                currOrigin = B.Clone();
            }
            return(segs);
        }
Пример #38
0
        /// <summary>
        /// Send love to screen
        /// </summary>
        public void Fly()
        {
            _sub.SpriteBatch.Begin();

            var firstSquare = new V2(_sub.Camera.Location.X / _loader.TileStepX, _sub.Camera.Location.Y / _loader.TileStepY);
            int firstX      = (int)firstSquare.X;
            int firstY      = (int)firstSquare.Y;

            var squareOffset = new V2(_sub.Camera.Location.X % _loader.TileStepX, _sub.Camera.Location.Y % _loader.TileStepY);
            int offsetX      = (int)squareOffset.X;
            int offsetY      = (int)squareOffset.Y;

            _tileRenderer.Render(_sub.SpriteBatch, new V2(0f, 0f));

            _sub.SpriteBatch.End();
        }
Пример #39
0
        public static async Task <T?> TryConnectAsync <T>(Endpoint?Endpoint, OutOfProcessClientOptions?Options = default) where T : class
        {
            var ret = default(T);

            if (Endpoint is { } V1&& TryGetProvider(Endpoint?.Provider) is { } V2)
            {
                try {
                    ret = await V2.ConnectAsync <T>(V1, Options)
                          .DefaultAwait()
                    ;
                } catch {
                }
            }

            return(ret);
        }
Пример #40
0
        public bool IsValid()
        {
            bool result;

            if (V1.IsSame(V2) || V1.IsSame(V3) || V2.IsSame(V3))
            {
                result = false;
            }
            else
            {
                Vector3d vector = V1.Subtract(V2);
                Vector3d target = V1.Subtract(V3);
                result = !vector.IsParallel(target);
            }
            return(result);
        }
Пример #41
0
        static void Main(string[] args)
        {
            V1             v1      = new V1();
            V2             v2      = new V2();
            List <IRegion> regions = new List <IRegion>()
            {
                v1, v2
            };
            RegionPipe pipe   = new RegionPipe(regions);
            string     result = pipe.Run(string.Empty) as string;

            Console.WriteLine("=========THE PIPE FINISHED RUNNING=========");
            Console.WriteLine("V1 output: \"{0}\", Elapsed Time: {1}", v1.Result, v1.ElapsedTime);
            Console.WriteLine("V2 output: \"{0}\", Elapsed Time: {1}", v2.Result, v2.ElapsedTime);
            Console.WriteLine("Pipe output: \"{0}\"", result);
            Console.ReadLine();
        }
        public ABFPVertex()
        {
            ID       = -1;
            IsBorder = false;

            Position = new V3();
            Normal   = new V3();
            UV       = new V2();
            UVA1     = new V4();
            UVA2     = new V4();
            UVA3     = new V4();
            UVA4     = new V4();

            SDEF_C  = new V3();
            SDEF_R0 = new V3();
            SDEF_R1 = new V3();
        }
        public override Tuple<V3, V3> DerivativePoint(V2 uv)
        {
            V2 uvS = UV(uv); // uv sphere

            V3 dPdu = new V3(
                x: -Radius * Mathf.Cos(uvS.V) * Mathf.Sin(uvS.U),
                y: Radius * Mathf.Cos(uvS.V) * Mathf.Cos(uvS.U),
                z: 0
            );
            dPdu.Normalize();

            V3 dPdv = new V3(
                x: -Radius * Mathf.Sin(uvS.V) * Mathf.Cos(uvS.U),
                y: -Radius * Mathf.Sin(uvS.V) * Mathf.Sin(uvS.U),
                z: Radius * Mathf.Cos(uvS.V)
            );
            dPdv.Normalize();

            return new Tuple<V3,V3>(dPdu, dPdv);
        }
        /// Computes the diffuse and specular components of the Phong
        /// reflection model.
        /// @Note Avoids code duplication in ComputePointLight and
        /// ComputeDirectionalLight.
        private Color ComputeDiffuseSpecular(
            Light l, Object3D obj, V3 p, V2 uv, V3 incidentVec
        )
        {
            V3 normalVec = obj.Normal(p, uv);

            V3 reflectedVec = incidentVec.ReflectedVector(normalVec);
            reflectedVec.Normalize();

            V3 viewingVec = CameraPos - p;
            viewingVec.Normalize();

            Color diffuseIllu = ComputeDiffuse(
                l, incidentVec, normalVec, obj, uv
            );
            Color specularIllu = ComputeSpecular(
                l, reflectedVec, normalVec, obj, uv
            );

            return diffuseIllu + specularIllu;
        }
        /// Renders one object.
        private void RenderObject(Object3D obj)
        {
            for (float u = 0.0f ; u < 1.0f ; u += 0.001f) {
                for (float v = 0.0f ; v < 1.0f ; v += 0.001f) {
                    V2 uv = new V2(u,v);
                    V3 p = obj.Point(uv);

                    V3 pScreen = new V3(
                        x: p.X,
                        y: Canvas.Height - p.Z,
                        z: p.Y
                    );
                    bool objectVisible = Set(pScreen);

                    if (objectVisible) {
                        Color illumination = Scene.IlluModel.Compute(
                            Scene.Lights, obj, p, uv
                        );

                        Canvas.DrawPixel(pScreen, illumination);
                    }
                }
            }
        }
 /// Retrieves uv values in the ranges specific to a rectangle.
 /// u: [0;1] -> [-0.5 ; 0.5]
 /// v: [0;1] -> [-0.5 ; 0.5]
 public override V2 UV(V2 uv)
 {
     return new V2 (
         u: uv.U - 0.5f,
         v: uv.V - 0.5f
     );
 }
        private Color ComputeSpecular(
            Light l, V3 reflectedVec, V3 viewingVec, Object3D obj, V2 uv
        )
        {
            Color specularIllu = new Color(0, 0, 0);
            if (reflectedVec * viewingVec > 0.0f) {
                specularIllu = l.Intensity * obj.Material.KSpecular *
                     Mathf.Pow(
                        reflectedVec * viewingVec,
                        obj.Material.Shininess
                     );
            }

            return specularIllu;
        }
Пример #48
0
        public void Render(ISpriteBatch spriteBatch, V2 cameraPosition)
        {
            spriteBatch.Begin();

            for (int i = 0; i < positionedWorldCells.Length; i++)
            {
                if (positionedWorldCells[i] == null)
                    continue;

                for (int j = 0; j < positionedWorldCells[i].Count; j++)
                {
                    var cell = positionedWorldCells[i][j];

                    if (cell.Tile == null)
                        continue;

                    spriteBatch.Draw(cell.Tile.Texture,
                        new Rect(0, 0, TileWidth, TileHeight),
                        new Rect((int)cell.Position.X, (int)cell.Position.Y, TileWidth, TileHeight),
                        0f,
                        baseDepth - ((i * 100) + j) * HeightRowDepthMod);

                    spriteBatch.DrawString(SysCore.SystemFont, cell.Position.X + ", " + cell.Position.Y, new V2(cell.Position.X, cell.Position.Y), new V4(255), 0f, 1f, 1f);

                }
            }

            spriteBatch.End();
        }
        /// Returns this object's normal altered by the Bump Map attached to
        /// this object's material.
        protected V3 AlteredNormal(V3 p, V2 uv)
        {
            V2 dh = Material.BumpMap.Bump(uv);

            Tuple<V3,V3> dP = DerivativePoint(uv);
            V3 dPdu = dP.Item1;
            V3 dPdv = dP.Item2;

            V3 n = Normal(p);
            V3 alteredN = n + Material.KBump * (
                (dPdu ^ n * dh.V) +
                (n * dh.U ^ dPdv)
            );
            alteredN.Normalize();

            return alteredN;
        }
        public override V3 Point(V2 uv)
        {
            V2 uvR = UV(uv); // uv rectangle

            return Center + (uvR.U * VA) + (uvR.V * VB);
        }
        public V2.IShipStationService CreateServiceV2( V2.Models.ShipStationCredentials credentials )
        {
            Condition.Requires( credentials, "credentials" ).IsNotNull();

            return new V2.ShipStationService( credentials );
        }
 /// Retrieves uv values in the ranges specific to a sphere.
 /// u: [0;1] -> [0;2PI]
 /// v: [0;1] -> [-PI/2;PI/2]
 public override V2 UV(V2 uv)
 {
     return new V2 (
         u: uv.U * 2 * Mathf.PI,
         v: (uv.V - 0.5f) * Mathf.PI
     );
 }
        /// Recursivly raytrace to get the color resulting from the refracted
        /// light component for the specified collisionPoint.
        private Color RefractionColor(
            V3 incidentVec, V3 collisionPoint, V2 collisionUV,
            Object3D collidedObj, int depth
        )
        {
            if (!collidedObj.Material.IsTransparent()) { return Color.Black; }

            V3 normal = collidedObj.Normal(collisionPoint, collisionUV);

            Ray refractionRay = new Ray(
                origin: collisionPoint,
                direction: incidentVec.RefractedVector(
                    normalVec: normal,
                    n1: Scene.RefractiveIndex,
                    n2: collidedObj.Material.RefractiveIndex
                ),
                originObject: null
            );

            Color refractionColor = Raytrace(refractionRay, depth - 1);
            if (refractionColor == null) { return Color.Black; }

            return collidedObj.Material.Transparency * refractionColor;
        }
 public abstract Color ComputeDirectionalLight(
     DirectionalLight dL, Object3D obj, V3 p, V2 uv
 );
 public abstract Color ComputePointLight(
     PointLight pL, Object3D obj, V3 p, V2 uv
 );
 public abstract Color ComputeAmbientLight(
     AmbientLight aL, Object3D obj, V3 p, V2 uv
 );
        public override V3 Point(V2 uv)
        {
            V2 uvS = UV(uv); // uv sphere

            return new V3(
                x: Center.X + (Radius * Mathf.Cos(uvS.V) * Mathf.Cos(uvS.U)),
                y: Center.Y + (Radius * Mathf.Cos(uvS.V) * Mathf.Sin(uvS.U)),
                z: Center.Z + (Radius * Mathf.Sin(uvS.V))
            );
        }
        /// Recursivly raytrace to get the color resulting from the reflected
        /// light component for the specified collisionPoint.
        private Color ReflectionColor(
            V3 incidentVec, V3 collisionPoint, V2 collisionUV,
            Object3D collidedObj, int depth
        )
        {
            if (!collidedObj.Material.IsReflective()) { return Color.Black; }

            V3 normal = collidedObj.Normal(collisionPoint, collisionUV);
            Ray reflectionRay = new Ray(
                origin:       collisionPoint,
                direction:    incidentVec.ReflectedVector(normal),
                originObject: collidedObj
            );

            Color reflectionColor = Raytrace(reflectionRay, depth - 1);
            if (reflectionColor == null) { return Color.Black; }

            return collidedObj.Material.Reflection * reflectionColor;
        }
 /// Retrieves uv values in the ranges specific to this 3D object.
 public abstract V2 UV(V2 uv);
 /// Computes the ambient component of the Phong reflection model for
 /// an ambient light.
 public override Color ComputeAmbientLight(
     AmbientLight aL, Object3D obj, V3 p, V2 uv
 )
 {
     return obj.TextureColor(uv) * aL.Intensity * obj.Material.KAmbient;
 }