Exemple #1
0
    static public void DrawTrianglef(float x0, float y0, float x1, float y1, float x2, float y2, Vector2D offset, float z = 0f)
    {
        GL.PushMatrix();
        defaultMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        GL.Color(setColor);

        Max2DMatrix.DrawTriangle(x0, y0, x1, y1, x2, y2, offset, z);

        GL.End();
        GL.PopMatrix();
    }
Exemple #2
0
 void MoveForwards(float delta)
 {
     _transform.position += delta * _transform.forward;
 }
Exemple #3
0
 void ChangePitch(float delta)
 {
     _pitch += delta;
     WrapAngle(ref _pitch);
     _transform.localEulerAngles = new Vector3(_pitch, _yaw, 0);
 }
Exemple #4
0
 public SobelFilterY()
 {
     kernel = new float[, ] {
         { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 }
     };
 }
Exemple #5
0
        public void pidControl()
        {
            Console.WriteLine("iter\tnormVal\terror\tpid_val\tpower");

//			while (!Button.ESCAPE.isDown())
//			while (true)
            while (iter++ < max_iter)
            {
//				int normVal = ls.readNormalizedValue();
                int normVal = ev3.getAngularVelocity();

                // Proportional Error:
                int error = normVal - offset;
                // Adjust far and near light readings:
//				if (error < 0) error = (int)(error * 1.8F);

                // Integral Error:
                int_error = ((int_error + error) * 2) / 3;

                // Derivative Error:
                int deriv_error = error - prev_error;
                prev_error = error;

                int pid_val = (int)(KP * error + KI * int_error + KD * deriv_error) / SCALE_PID;

                if (pid_val > 100)
                {
                    pid_val = 100;
                }
                if (pid_val < -100)
                {
                    pid_val = -100;
                }

                // Power derived from PID value:
                int power = Math.Abs(pid_val);
                power = SPEED + (power * NORM_POWER) / SCALE_POWER;                 // NORMALIZE POWER

                Console.Write(iter + "\t" + normVal + "\t" + error + "\t"
                              + pid_val + "\t" + power + "\t");

                if (pid_val >= 0)
                {
                    Console.WriteLine("Forward");
                    ev3.onMotorA(power);
                    ev3.onMotorD(power);
//					MotorPort.B.controlMotor(power, BasicMotorPort.FORWARD);
//					MotorPort.C.controlMotor(power, BasicMotorPort.FORWARD);
                }
                else
                {
                    Console.WriteLine("Backward");
                    ev3.onMotorA(-1 * power);
                    ev3.onMotorD(-1 * power);
//					MotorPort.B.controlMotor(power, BasicMotorPort.BACKWARD);
//					MotorPort.C.controlMotor(power, BasicMotorPort.BACKWARD);
                }

//				Thread.Sleep (SLEEP);
            }
        }
Exemple #6
0
        /// <summary>
        /// Rotates an image
        /// </summary>
        /// <param name="image">Image to rotate</param>
        /// <param name="angleInDegrees">Number of degrees to rotate in counter clockwise direction</param>
        /// <param name="mode">Pixel resampling method</param>
        /// <returns>Rotated image</returns>
        public static Shared <Image> Rotate(this Image image, float angleInDegrees, SamplingMode mode)
        {
            float ca   = (float)System.Math.Cos(angleInDegrees * System.Math.PI / 180.0f);
            float sa   = (float)System.Math.Sin(angleInDegrees * System.Math.PI / 180.0f);
            float minx = 0.0f;
            float miny = 0.0f;
            float maxx = 0.0f;
            float maxy = 0.0f;
            float x    = image.Width - 1;
            float y    = 0.0f;
            float nx   = (x * ca) - (y * sa);
            float ny   = (x * sa) + (y * ca);

            if (nx < minx)
            {
                minx = nx;
            }

            if (nx > maxx)
            {
                maxx = nx;
            }

            if (ny < miny)
            {
                miny = ny;
            }

            if (ny > maxy)
            {
                maxy = ny;
            }

            x  = image.Width - 1;
            y  = image.Height - 1;
            nx = (x * ca) - (y * sa);
            ny = (x * sa) + (y * ca);
            if (nx < minx)
            {
                minx = nx;
            }

            if (nx > maxx)
            {
                maxx = nx;
            }

            if (ny < miny)
            {
                miny = ny;
            }

            if (ny > maxy)
            {
                maxy = ny;
            }

            x  = 0.0f;
            y  = image.Height - 1;
            nx = (x * ca) - (y * sa);
            ny = (x * sa) + (y * ca);
            if (nx < minx)
            {
                minx = nx;
            }

            if (nx > maxx)
            {
                maxx = nx;
            }

            if (ny < miny)
            {
                miny = ny;
            }

            if (ny > maxy)
            {
                maxy = ny;
            }

            int dstWidth  = (int)(maxx - minx + 1);
            int dstHeight = (int)(maxy - miny + 1);
            var bitmap    = new Bitmap(dstWidth, dstHeight);
            var graphics  = Graphics.FromImage(bitmap);

            graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            switch (mode)
            {
            case SamplingMode.Point:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
                break;

            case SamplingMode.Bilinear:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                break;

            case SamplingMode.Bicubic:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                break;
            }

            graphics.TranslateTransform(-minx, -miny);
            graphics.RotateTransform(angleInDegrees);
            graphics.DrawImage(image.ToManagedImage(), new Point(0, 0));
            return(ImagePool.GetOrCreate(bitmap));
        }
Exemple #7
0
        static void ResetAllLoadedMaterialKeywords(string descriptionPrefix, float progressScale, float progressOffset)
        {
            var materials = Resources.FindObjectsOfTypeAll <Material>();

            bool VSCEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);

            for (int i = 0, length = materials.Length; i < length; i++)
            {
                EditorUtility.DisplayProgressBar(
                    "Setup materials Keywords...",
                    string.Format("{0}{1} / {2} materials cleaned.", descriptionPrefix, i, length),
                    (i / (float)(length - 1)) * progressScale + progressOffset);

                CheckOutFile(VSCEnabled, materials[i]);
                HDEditorUtils.ResetMaterialKeywords(materials[i]);
            }
        }
Exemple #8
0
 void SetDelta(float newDelta)
 {
     delta = Mathf.Clamp(newDelta, -maxDelta, maxDelta);
 }
Exemple #9
0
 public void RandomizeDelta()
 {
     sign  = Mathf.Sign(Random.Range(-10, 10));
     delta = Random.Range(minDelta, maxDelta) * (1.0f + difficulty / 20.0f) * sign;
 }
Exemple #10
0
 //reset round
 void resetround()
 {
     run   = false;
     timer = 0;
 }
Exemple #11
0
 // Update is called once per frame
 void Update()
 {
     Shader.SetGlobalFloat("_Timer", time);
     time += delta;
 }
		public void StartTriangulation()
		{
			if (dg == null)
				return;
			mainRooms.Clear();
			float mean = dg.rooms.Average(o => o.rect.size.sqrMagnitude);
			var roomFromTheBiggest = dg.rooms.OrderBy(o => o.rect.size.sqrMagnitude).ToList();
			roomFromTheBiggest.Reverse();
			foreach(Room r in roomFromTheBiggest)
			{
				if(r.rect.size.sqrMagnitude >= mean)
				{
					mainRooms.Add(r);
				}
				if (mainRooms.Count >= dg.rooms.Count * mainRoomSize)
					break;
			}

			List<Vector2> m_points = mainRooms.Select(o => o.rect.center).ToList();
			List<uint> colors = new List<uint>();
			foreach (Vector2 v in m_points)
				colors.Add(0);

			v = new Voronoi(m_points, colors, new Rect(0, 0, -999999, 999999));

			m_delaunayTriangulation = v.DelaunayTriangulation();
			m_spanningTree = v.SpanningTree(KruskalType.MINIMUM);

			List<LineSegment> trisLeft = new List<LineSegment>();
			foreach(LineSegment d in m_delaunayTriangulation)
			{
				bool safeToAdd = true;
				foreach(LineSegment s in m_spanningTree)
				{
					if ((d.p0 == s.p0 && d.p1 == s.p1) || (d.p0 == s.p1 && d.p1 == s.p0)) 
					{
						safeToAdd = false;
						break;
					}
				}
				if(safeToAdd)
					trisLeft.Add(d);
			}

			trisLeft = trisLeft.OrderBy(o => (Vector2.SqrMagnitude((Vector2)(o.p0 - o.p1)))).ToList();
			for(int i = 0; i < (int)(trisLeft.Count * keepConnection); i++)
			{
				m_spanningTree.Add(trisLeft[i]);
			}
			
			dg.roomConnection.Clear();
			foreach(LineSegment l in m_spanningTree)
			{
				if (dg.roomConnection.ContainsKey(l))
					continue;

				Room r1 = null, r2 = null;
				foreach(Room r in mainRooms)
				{
					if (r.rect.center == l.p0)
						r1 = r;
					else if (r.rect.center == l.p1)
						r2 = r;
				}

				if(r1 == null || r2 == null)
				{
#if DEBUG_MODE
					Debug.Log("Dude, something doesn't right! Room is not detected in triangulation! Check here");
#endif
				}
				else 
				{
					dg.roomConnection.Add(l, new List<Room>(2) { r1, r2 });
				}
			}
		}
Exemple #13
0
    static public void DrawMesh(Material material, Mesh mesh, Transform transform, Vector2D offset, float z = 0f)
    {
        if (mesh == null)
        {
            return;
        }

        GL.PushMatrix();
        material.SetPass(0);
        GL.Begin(GL.TRIANGLES);

        for (int i = 0; i < mesh.triangles.GetLength(0); i = i + 3)
        {
            Vector3 a = transform.TransformPoint(mesh.vertices [mesh.triangles [i]]);
            Vector3 b = transform.TransformPoint(mesh.vertices [mesh.triangles [i + 1]]);
            Vector3 c = transform.TransformPoint(mesh.vertices [mesh.triangles [i + 2]]);
            Max2DMatrix.DrawTriangle(a.x, a.y, b.x, b.y, c.x, c.y, offset, z);
        }

        GL.End();
        GL.PopMatrix();
    }
Exemple #14
0
    static public void DrawStrippedLine(List <Vector2D> pointsList, float minVertsDistance, float z = 0f, bool full = false, Vector2D offset = null)
    {
        if (offset == null)
        {
            offset = new Vector2D(0, 0);
        }

        Vector2D vA = null, vB = null;

        if (setBorder == true)
        {
            Color tmcColor = setColor;
            float tmpWidth = lineWidth;

            GL.PushMatrix();
            SetColor(Color.black);
            lineMaterial.SetPass(0);
            GL.Begin(GL.QUADS);

            lineWidth = 2f * tmpWidth;

            foreach (Pair2D id in Pair2D.GetList(pointsList, full))
            {
                vA = new Vector2D(id.A + offset);
                vB = new Vector2D(id.B + offset);

                vA.Push(Vector2D.Atan2(id.A, id.B), -minVertsDistance / 5 * setScale);
                vB.Push(Vector2D.Atan2(id.A, id.B), minVertsDistance / 5 * setScale);

                Max2DMatrix.DrawLineImage(new Pair2D(vA, vB), z);
            }

            GL.End();
            GL.PopMatrix();

            SetColor(tmcColor);
            lineWidth = tmpWidth;
        }

        GL.PushMatrix();
        lineMaterial.SetPass(0);
        GL.Begin(GL.QUADS);

        foreach (Pair2D id in Pair2D.GetList(pointsList, full))
        {
            vA = new Vector2D(id.A + offset);
            vB = new Vector2D(id.B + offset);

            vA.Push(Vector2D.Atan2(id.A, id.B), -minVertsDistance / 4 * setScale);
            vB.Push(Vector2D.Atan2(id.A, id.B), minVertsDistance / 4 * setScale);

            Max2DMatrix.DrawLineImage(new Pair2D(vA, vB), z);
        }

        GL.End();
        GL.PopMatrix();
    }
Exemple #15
0
		private object getAsFloat(ILuaState luaState,int stackPos) 
		{
			float retVal=(float)LuaDLL.lua_tonumber(luaState,stackPos);
			if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null;
			return retVal;
		}
	// Use this for initialization
	void Start () {
		var particleSystem = GetComponent<ParticleSystem>();
		float t = particleSystem.main.duration
			+ particleSystem.main.startLifetime.constant;
		Destroy(gameObject, t);
	}
    protected IEnumerator DoCreateEffect(GameObject prefab, Vector3 worldPos, Quaternion rotation, float length, EffectDelegate endDel)
    {
        GameObject go = CreateEffect(prefab);

        go.name = prefab.name + "_Inst";
        go.transform.position = worldPos;
        go.transform.rotation = rotation;

        yield return(new WaitForSeconds(length));

        if (null != endDel)
        {
            endDel(go);
        }

        Destroy(go);
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            float x = position.x;
            float y = position.y;
            float inspectorWidth = position.width;

            // Draw label


            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;
            EditorGUI.indentLevel = 0;

            var items = property.FindPropertyRelative("items");
            var titles = new string[] {"Transform", "", "", ""};
            var props = new string[] {"transform", "^", "v", "-"};
            var widths = new float[] {.7f, .1f, .1f, .1f};
            float lineHeight = 18;
            bool changedLength = false;
            if (items.arraySize > 0)
            {
                for (int i = 0; i < items.arraySize; i++)
                {
                    var item = items.GetArrayElementAtIndex(i);

                    float rowX = x;
                    for (int n = 0; n < props.Length; ++n)
                    {
                        float w = widths[n]*inspectorWidth;

                        // Calculate rects
                        Rect rect = new Rect(rowX, y, w, lineHeight);
                        rowX += w;

                        if (i == -1)
                        {
                            EditorGUI.LabelField(rect, titles[n]);
                        }
                        else
                        {
                            if (n == 0)
                            {
                                EditorGUI.ObjectField(rect, item.objectReferenceValue, typeof (Transform), true);
                            }
                            else
                            {
                                if (GUI.Button(rect, props[n]))
                                {
                                    switch (props[n])
                                    {
                                        case "-":
                                            items.DeleteArrayElementAtIndex(i);
                                            items.DeleteArrayElementAtIndex(i);
                                            changedLength = true;
                                            break;
                                        case "v":
                                            if (i > 0)
                                            {
                                                items.MoveArrayElement(i, i + 1);
                                            }
                                            break;
                                        case "^":
                                            if (i < items.arraySize - 1)
                                            {
                                                items.MoveArrayElement(i, i - 1);
                                            }
                                            break;
                                    }
                                }
                            }
                        }
                    }

                    y += lineHeight + spacing;
                    if (changedLength)
                    {
                        break;
                    }
                }
            }
            else
            {
                // add button
                var addButtonRect = new Rect((x + position.width) - widths[widths.Length - 1]*inspectorWidth, y,
                                             widths[widths.Length - 1]*inspectorWidth, lineHeight);
                if (GUI.Button(addButtonRect, "+"))
                {
                    items.InsertArrayElementAtIndex(items.arraySize);
                }

                y += lineHeight + spacing;
            }

            // add all button
            var addAllButtonRect = new Rect(x, y, inspectorWidth, lineHeight);
            if (GUI.Button(addAllButtonRect, "Assign using all child objects"))
            {
                var circuit = property.FindPropertyRelative("circuit").objectReferenceValue as WaypointCircuit;
                var children = new Transform[circuit.transform.childCount];
                int n = 0;
                foreach (Transform child in circuit.transform)
                {
                    children[n++] = child;
                }
                Array.Sort(children, new TransformNameComparer());
                circuit.waypointList.items = new Transform[children.Length];
                for (n = 0; n < children.Length; ++n)
                {
                    circuit.waypointList.items[n] = children[n];
                }
            }
            y += lineHeight + spacing;

            // rename all button
            var renameButtonRect = new Rect(x, y, inspectorWidth, lineHeight);
            if (GUI.Button(renameButtonRect, "Auto Rename numerically from this order"))
            {
                var circuit = property.FindPropertyRelative("circuit").objectReferenceValue as WaypointCircuit;
                int n = 0;
                foreach (Transform child in circuit.waypointList.items)
                {
                    child.name = "Waypoint " + (n++).ToString("000");
                }
            }
            y += lineHeight + spacing;

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
Exemple #19
0
        static void UpdateHeightMapParametrization()
        {
            try
            {
                var matIds = AssetDatabase.FindAssets("t:Material");

                for (int i = 0, length = matIds.Length; i < length; i++)
                {
                    var path = AssetDatabase.GUIDToAssetPath(matIds[i]);
                    var mat  = AssetDatabase.LoadAssetAtPath <Material>(path);

                    EditorUtility.DisplayProgressBar(
                        "Updating Materials...",
                        string.Format("{0} / {1} materials updated.", i, length),
                        i / (float)(length - 1));

                    bool VSCEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);

                    if (mat.shader.name == "HDRenderPipeline/LitTessellation" ||
                        mat.shader.name == "HDRenderPipeline/Lit")
                    {
                        // Need only test one of the new properties
                        if (mat.HasProperty("_HeightPoMAmplitude"))
                        {
                            CheckOutFile(VSCEnabled, mat);

                            float valueMax  = mat.GetFloat("_HeightMax");
                            float valueMin  = mat.GetFloat("_HeightMin");
                            float center    = mat.GetFloat("_HeightCenter");
                            float amplitude = valueMax - valueMin;
                            mat.SetInt("_HeightMapParametrization", 1);
                            mat.SetFloat("_HeightPoMAmplitude", amplitude);
                            mat.SetFloat("_HeightTessAmplitude", amplitude);
                            mat.SetFloat("_HeightOffset", 0.0f);
                            mat.SetFloat("_HeightTessCenter", center);

                            BaseLitGUI.DisplacementMode displaceMode = (BaseLitGUI.DisplacementMode)mat.GetInt("_DisplacementMode");
                            if (displaceMode == BaseLitGUI.DisplacementMode.Pixel)
                            {
                                mat.SetFloat("_HeightCenter", 1.0f); // With PoM this is always 1.0f. We set it here to avoid having to open the UI to update it.
                            }

                            EditorUtility.SetDirty(mat);
                        }
                    }
                    else if (mat.shader.name == "HDRenderPipeline/LayeredLit" ||
                             mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
                    {
                        int numLayer = (int)mat.GetFloat("_LayerCount");

                        if (mat.HasProperty("_HeightPoMAmplitude0"))
                        {
                            CheckOutFile(VSCEnabled, mat);

                            for (int x = 0; x < numLayer; ++x)
                            {
                                float valueMax  = mat.GetFloat("_HeightMax" + x);
                                float valueMin  = mat.GetFloat("_HeightMin" + x);
                                float center    = mat.GetFloat("_HeightCenter" + x);
                                float amplitude = valueMax - valueMin;
                                mat.SetInt("_HeightMapParametrization" + x, 1);
                                mat.SetFloat("_HeightPoMAmplitude" + x, valueMax - valueMin);
                                mat.SetFloat("_HeightTessAmplitude" + x, valueMax - valueMin);
                                mat.SetFloat("_HeightOffset" + x, 0.0f);
                                mat.SetFloat("_HeightTessCenter" + x, center);

                                BaseLitGUI.DisplacementMode displaceMode = (BaseLitGUI.DisplacementMode)mat.GetInt("_DisplacementMode");
                                if (displaceMode == BaseLitGUI.DisplacementMode.Pixel)
                                {
                                    mat.SetFloat("_HeightCenter" + x, 1.0f); // With PoM this is always 1.0f. We set it here to avoid having to open the UI to update it.
                                }
                            }

                            EditorUtility.SetDirty(mat);
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     SerializedProperty items = property.FindPropertyRelative("items");
     float lineAndSpace = lineHeight + spacing;
     return 40 + (items.arraySize*lineAndSpace) + lineAndSpace;
 }
Exemple #21
0
 public SobelFilterX()
 {
     kernel = new float[, ] {
         { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 }
     };
 }
Exemple #22
0
 private void Start()
 {
     currentHealth = MaxHealth;
 }
Exemple #23
0
 private void SetWeight(int index, float value)
 {
     var clamped = Mathf.Clamp(value, 0, 100);
     _renderer.SetBlendShapeWeight(index, clamped);
 }
Exemple #24
0
 public void setHealth(float amount)
 {
     currentHealth = Mathf.Clamp(amount, 0, MaxHealth);
     checkDeath();
 }
Exemple #25
0
	void FixedUpdate () 
	{
		float v = Input.GetAxisRaw(axis);
		GetComponent<Rigidbody2D>().velocity = new Vector2(0, v) * speed;
	}
 public static void ShiftAlignmentPlane(float y)
 {
     AlignmentPlane.Shift(y);
 }
Exemple #27
0
 void Strafe(float delta)
 {
     transform.position += delta * _transform.right;
 }
 public static void SetAlignmentPlane(float y)
 {
     AlignmentPlane.Set(y);
 }
		public void Flatten( object matrix, float flatness )
		{
			var paramTypes = new System.Type[] { matrix.GetType(), flatness.GetType() };
			var method = ReflectionUtils.getMethodInfo( _graphicsPath, "Flatten", paramTypes );
			method.Invoke( _graphicsPath, new object[] { matrix, flatness } );
		}
Exemple #30
0
    ///// Geometry & Test Functions /////


    static public void DrawTriangle(Vector2D p0, Vector2D p1, Vector2D p2, Vector2D offset, float z = 0f)
    {
        DrawTrianglef((float)p0.x, (float)p0.y, (float)p1.x, (float)p1.y, (float)p2.x, (float)p2.y, offset, z);
    }