Example #1
0
public Float2 pow(Float2 asd,Float p){
	asd.x = Mathf.Pow(asd.x,p);
	asd.y = Mathf.Pow(asd.y,p);
	return asd;
}
Example #2
0
public Float dot(Float2 asd,Float2 asd2){
	return asd.x*asd2.x+asd.y*asd2.y;
}
Example #3
0
//Float2 Interpolation_C2( Float2 x ) { return (x+0).Square().Square().Mul(x * ((x*6.0f).Sub(15.0f)).Add(10.0f)); }
//Float2 Interpolation_C2( Float2 x ) { return x * x * x * ((x * ((x * 6.0f) - 15.0f)) + 10.0f); }
//Float2 Interpolation_C2( Float2 x ) { return x*x*x*(x*(x*6f-15f)+10f); }
Float2 Interpolation_C2( Float2 x ) { return (x*x).Square()*((x*(x*6f-15f)).Add(10f)); }
Example #4
0
//Float2 Interpolation_C2( Float2 x ) { return (x*x).Square().Mul((x * ((x * 6.0f) - 15.0f)).Add(10.0f)); }
void FastHash2D(Float2 Pos,out Float4 hash_0, out Float4 hash_1, out Float4 hash_2){
	Float2 Offset = new Float2(26,161);
	Float Domain = 71f;
	Float3 SomeLargeFloats = new Float3(951.135664f,642.9478304f,803.202459f);
	Float4 P = new Float4(Pos,Pos+1);
	P = P.Sub(floor(P.Mul((1.0f/Domain)),true).Mul(Domain));
	P.Add(Offset.xyxy);
	P.Square();
	P = P.xzxz*P.yyww;
	hash_0 = frac(P*(1f/SomeLargeFloats.x),true);
	hash_1 = frac(P*(1f/SomeLargeFloats.y),true);
	hash_2 = frac(P*(1f/SomeLargeFloats.z),true);
}
Example #5
0
public float CellNoise(float X,float Y,float Jitter){
	Float2 P = new Float2(X,Y);
	Float2 Pi = floor(P,true);
	Float2 Pf = P.Sub(Pi);
	Float4 HashX, HashY;
	FastHash2D(Pi,out HashX,out HashY);
	HashX = (CellularWeightSamples(HashX).Mul(Jitter)).Add(0,1,0,1);
	HashY = (CellularWeightSamples(HashY).Mul(Jitter)).Add(0,0,1,1);
	Float4 dx = Pf.xxxx.Sub(HashX);
	Float4 dy = Pf.yyyy.Sub(HashY);
	Float4 d = dx.Square()+dy.Square();
	d.xy = min(d.xy,d.zw,false);
	return min(d.x,d.y,false).Mul(1.0f/1.125f);
}
Example #6
0
public void FastHash2D(Float2 Pos,out Float4 hash_0, out Float4 hash_1){
	//Float2 Offset = new Float2(26,161);
	float Domain = 71;
	Float2 SomeLargeFloats = new Float2(951.135664f,642.9478304f);
	Float4 P = new Float4(Pos.x,Pos.y,Pos.x+1,Pos.y+1);
	P = P-floor(P*(1.0f/Domain),false)*Domain;
	P.x += 26;
	P.y += 161;
	P.z += 26;
	P.w += 161;
	P.Mul(P);
	P = P.xzxz.Mul(P.yyww);
	hash_0 = frac(P*(1/SomeLargeFloats.x),false);
	hash_1 = frac(P*(1/SomeLargeFloats.y),false);
}
Example #7
0
public Float2 frac(Float2 s,bool SpawnNew){
	if (SpawnNew)
	return s-floor(s,true);
	else
	return s.Sub(floor(s,true));
}
Example #8
0
Float CubistNoise(float X,float Y,float Val1,float Val2)
{
	Float2 P = new Float2(X,Y);
	Float2 Pi = floor(P,true);
	Float4 Pf_Pfmin1 = P.xyxy.Sub(new Float4(Pi,Pi+1));
	Float4 HashX, HashY, HashValue;
	FastHash2D(Pi,out HashX,out HashY,out HashValue);
	Float4 GradX = HashX.Sub(0.499999f);
	Float4 GradY = HashY.Sub(0.499999f);
	Float4 GradRes = rsqrt(GradX*GradX+GradY*GradY)*(GradX*Pf_Pfmin1.xzxz+GradY*Pf_Pfmin1.yyww);
	GradRes = ( HashValue - 0.5f ).Mul( 1.0f / GradRes );
	
	GradRes.Mul(1.4142135623730950488016887242097f);
	Float2 blend = Interpolation_C2(Pf_Pfmin1.xy);
	Float4 blend2 = new Float4(blend,new Float2(1.0f-blend));
	Float final = (dot(GradRes,blend2.zxzx*blend2.wwyy));
	//return Interpolation_C2(new Float2(0.6f));
	return clamp((final.Add(Val1)).Mul(Val2),0.0f,1.0f);
}
Example #9
0
		public static void ReadFloat2(this Stream stream, out Float2 v)
		{
			v.X = stream.ReadSingle();
			v.Y = stream.ReadSingle();
			if (float.IsInfinity(v.X) || float.IsInfinity(v.Y))
			{
				throw new BspFormatException(string.Format("Wrong vertex data {{{0}, {1}}}", v.X, v.Y));
			}
		}
Example #10
0
		private void BuildFace(ref SourceFace face, BspSubmeshStreams subMesh)
		{
			Vertex[] faceVertices = new Vertex[face.numedges];

			var plane = this.planes[face.planenum];
			var texture_id = this.texInfo[face.texinfo].texdata;

			Float2 minUV0 = new Float2(float.MaxValue, float.MaxValue);
			Float2 minUV1 = new Float2(float.MaxValue, float.MaxValue);
			Float2 maxUV1 = new Float2(float.MinValue, float.MinValue);
			int nextShouldBe = -1;
			for (int index = 0; index < faceVertices.Length; index++)
			{
				var listOfEdgesIndex = face.firstedge + index;
				if (listOfEdgesIndex >= this.listOfEdges.Length)
				{
					throw new BspFormatException(
						string.Format("Edge list index {0} is out of range [0..{1}]", listOfEdgesIndex, this.listOfEdges.Length - 1));
				}

				var edgeIndex = this.listOfEdges[listOfEdgesIndex];
				if (edgeIndex >= this.edges.Length)
				{
					throw new BspFormatException(
						string.Format("Edge index {0} is out of range [0..{1}]", edgeIndex, this.edges.Length - 1));
				}

				SourceEdge edge;
				if (edgeIndex >= 0)
				{
					edge = this.edges[edgeIndex];
				}
				else
				{
					var flippedEdge = this.edges[-edgeIndex];
					edge = new SourceEdge { vertex0 = flippedEdge.vertex1, vertex1 = flippedEdge.vertex0 };
				}
				var edgesvertex0 = edge.vertex0;
				if (edgesvertex0 >= this.vertices.Length)
				{
					throw new BspFormatException(
						string.Format("Vertex index {0} is out of range [0..{1}]", edgesvertex0, this.vertices.Length - 1));
				}
				var edgesvertex1 = edge.vertex1;
				if (edgesvertex1 >= this.vertices.Length)
				{
					throw new BspFormatException(
						string.Format("Vertex index {0} is out of range [0..{1}]", edgesvertex1, this.vertices.Length - 1));
				}
				if (nextShouldBe >= 0 && nextShouldBe != edgesvertex0)
				{
					throw new BspFormatException(string.Format("Wrong edge order"));
				}
				nextShouldBe = edgesvertex1;
				Vertex vertex;
				this.BuildVertex(
					this.vertices[(short)edgesvertex0],
					plane.normal,
					//(face.side == 0) ? plane.normal : -plane.normal,
					face,
					ref this.texInfo[face.texinfo],
					out vertex);
				faceVertices[index] = vertex;
				if (minUV0.X > vertex.UV0.X)
				{
					minUV0.X = vertex.UV0.X;
				}
				if (minUV0.Y > vertex.UV0.Y)
				{
					minUV0.Y = vertex.UV0.Y;
				}
				if (minUV1.X > vertex.UV1.X)
				{
					minUV1.X = vertex.UV1.X;
				}
				if (minUV1.Y > vertex.UV1.Y)
				{
					minUV1.Y = vertex.UV1.Y;
				}
				if (maxUV1.X < vertex.UV1.X)
				{
					maxUV1.X = vertex.UV1.X;
				}
				if (maxUV1.Y < vertex.UV1.Y)
				{
					maxUV1.Y = vertex.UV1.Y;
				}
			}
			if (this.textures[texture_id].name == "TOOLS/TOOLSSKYBOX")
			{
				minUV0.X = 0;
				minUV0.Y = 0;
				for (int j = 0; j < (int)face.numedges; ++j)
				{
					faceVertices[j].UV0 = new Float3(0, 0, 0);
				}
			}

			int[] indices = new int[faceVertices.Length];
			for (int j = 0; j < faceVertices.Length; ++j)
			{
				meshStreams.Positions.Add(faceVertices[j].Position);
				meshStreams.Normals.Add(faceVertices[j].Normal);
				meshStreams.Colors.Add(faceVertices[j].Color);
				meshStreams.TexCoord0.Add(new Float2(faceVertices[j].UV0.X, faceVertices[j].UV0.Y));
				meshStreams.TexCoord1.Add(new Float2(faceVertices[j].UV1.X, faceVertices[j].UV1.Y));
			}
			for (int j = 1; j < faceVertices.Length - 1; ++j)
			{
				subMesh.AddToAllStreams(indices[0]);
				subMesh.AddToAllStreams(indices[j]);
				subMesh.AddToAllStreams(indices[j + 1]);
			}
		}
Example #11
0
            /// <inheritdoc />
            public override void OnShowSecondaryContextMenu(FlaxEditor.GUI.ContextMenu.ContextMenu menu, Float2 location)
            {
                base.OnShowSecondaryContextMenu(menu, location);

                if (GetSelected() == null)
                {
                    return;
                }
                menu.AddSeparator();
                menu.AddButton("Find references...", OnFindReferences);
            }
Example #12
0
 public Float3(float x, Float2 yz)
 {
     this.X = x;
     this.Y = yz.X;
     this.Z = yz.Y;
 }
Example #13
0
        protected override void Reorient(Float2 position, Float2 dimension)
        {
            base.Reorient(position, dimension);
            int count = ChildCount;

            if (count == 0)
            {
                transform.PreferedHeight = null;
                return;
            }

            float marginSize = Margins ? Theme.MediumMargin : 0f;
            float spaceSize  = Spaces ? Theme.MediumMargin : 0f;

            if (Horizontal)
            {
                float margin = marginSize / Dimension.x;
                float space  = spaceSize / Dimension.x;

                float total = 1f - margin * 2f - (count - 1) * space;

                float width   = total / count;
                float current = margin;

                foreach (AreaUI child in LoopForward())
                {
                    Transform target = child.transform;

                    target.LeftPercent  = current;
                    current            += width;
                    target.RightPercent = 1f - current;

                    target.HorizontalMargins = 0f;
                    target.VerticalPercents  = 0f;

                    target.TopMargin    = marginSize + PositiveMargin;
                    target.BottomMargin = marginSize + NegativeMargin;

                    current += space;
                }
            }
            else
            {
                float current = marginSize;

                foreach (AreaUI child in LoopForward())
                {
                    Transform target = child.transform;
                    float     height = target.PreferedHeight ?? Theme.LayoutHeight;

                    //Vertical layouts are controlled solely by margins
                    target.TopMargin    = current;
                    current            += height;
                    target.BottomMargin = -current;

                    target.TopPercent         = 0f;
                    target.BottomPercent      = 1f;
                    target.HorizontalPercents = 0f;

                    target.RightMargin = marginSize + PositiveMargin;
                    target.LeftMargin  = marginSize + NegativeMargin;

                    current += spaceSize;
                }

                transform.PreferedHeight = current + marginSize - spaceSize;
            }
        }
Example #14
0
 public BasicVertex(Float3 position, Float3 normal, Float2 textureCoordinates)
 {
     this.Position           = position;
     this.Normal             = normal;
     this.TextureCoordinates = textureCoordinates;
 }
Example #15
0
        /// <inheritdoc />
        public override void UpdateView(float dt, ref Vector3 moveDelta, ref Float2 mouseDelta, out bool centerMouse)
        {
            centerMouse = true;

            if (IsAnimatingMove)
            {
                return;
            }

            Viewport.GetInput(out var input);
            Viewport.GetPrevInput(out var prevInput);
            var transformGizmo = (Viewport as EditorGizmoViewport)?.Gizmos.Active as TransformGizmoBase;
            var isUsingGizmo   = transformGizmo != null && transformGizmo.ActiveAxis != TransformGizmoBase.Axis.None;

            // Get current view properties
            var yaw      = Viewport.Yaw;
            var pitch    = Viewport.Pitch;
            var position = Viewport.ViewPosition;
            var rotation = Viewport.ViewOrientation;

            // Compute base vectors for camera movement
            var forward = Vector3.Forward * rotation;
            var up      = Vector3.Up * rotation;
            var right   = Vector3.Cross(forward, up);

            // Dolly
            if (input.IsPanning || input.IsMoving || input.IsRotating)
            {
                Vector3.Transform(ref moveDelta, ref rotation, out Vector3 move);
                position += move;
            }

            // Pan
            if (input.IsPanning)
            {
                var panningSpeed = 0.8f;
                if (Viewport.InvertPanning)
                {
                    position += up * (mouseDelta.Y * panningSpeed);
                    position += right * (mouseDelta.X * panningSpeed);
                }
                else
                {
                    position -= right * (mouseDelta.X * panningSpeed);
                    position -= up * (mouseDelta.Y * panningSpeed);
                }
            }

            // Move
            if (input.IsMoving)
            {
                // Move camera over XZ plane
                var projectedForward = Vector3.Normalize(new Vector3(forward.X, 0, forward.Z));
                position -= projectedForward * mouseDelta.Y;
                yaw      += mouseDelta.X;
            }

            // Rotate or orbit
            if (input.IsRotating || (input.IsOrbiting && !isUsingGizmo && prevInput.IsOrbiting))
            {
                yaw   += mouseDelta.X;
                pitch += mouseDelta.Y;
            }

            // Zoom in/out
            if (input.IsZooming && !input.IsRotating)
            {
                position += forward * (Viewport.MouseWheelZoomSpeedFactor * input.MouseWheelDelta * 25.0f);
                if (input.IsAltDown)
                {
                    position += forward * (Viewport.MouseSpeed * 40 * Viewport.MousePositionDelta.ValuesSum);
                }
            }

            // Move camera with the gizmo
            if (input.IsOrbiting && isUsingGizmo)
            {
                centerMouse            = false;
                Viewport.ViewPosition += transformGizmo.LastDelta.Translation;
                return;
            }

            // Update view
            Viewport.Yaw   = yaw;
            Viewport.Pitch = pitch;
            if (input.IsOrbiting)
            {
                float   orbitRadius   = Mathf.Max((float)Vector3.Distance(ref position, ref TargetPoint), 0.0001f);
                Vector3 localPosition = Viewport.ViewDirection * (-1 * orbitRadius);
                Viewport.ViewPosition = TargetPoint + localPosition;
            }
            else
            {
                TargetPoint          += position - Viewport.ViewPosition;
                Viewport.ViewPosition = position;
            }
        }
Example #16
0
 public static Rect Scale(Rect r, Float2 scale)
 {
     return(new Rect(r.Left * scale.X, r.Top * scale.Y, r.Right * scale.X, r.Bottom * scale.Y));
 }
Example #17
0
 /// <summary>
 /// Show context menu over given control.
 /// </summary>
 /// <param name="parent">Parent control to attach to it.</param>
 /// <param name="location">Popup menu origin location in parent control coordinates.</param>
 /// <param name="startBox">The currently selected box that the new node will get connected to. Can be null</param>
 public void Show(Control parent, Float2 location, Elements.Box startBox)
 {
     _selectedBox = startBox;
     base.Show(parent, location);
 }
Example #18
0
	public Float4(Float2 xx,Float2 yy){
		x = xx.x;
		y = xx.y;
		z = yy.x;
		w = yy.y;
	}
Example #19
0
 public Float2Diff(Float2 first, Float2 second)
 {
     First = first;
     Second = second;
     Discrepancy = second.Module != 0.0f ? ((first - second) / second).Module : 0.0;
 }
Example #20
0
	public Float2 Sub(Float2 xx){
		x-=xx.x;
		y-=xx.y;
		return this;
	}
Example #21
0
	/*public Float2(Float xx,Float yy){
		x = xx.x;
		y = yy.x;
	}
	public Float2(Float xx){
		x = xx.x;
		y = xx.x;
	}*/
	public Float2(Float2 xx){
		x = xx.x;
		y = xx.y;
	}
Example #22
0
	public Float2 Div(Float2 xx){
		x/=xx.x;
		y/=xx.y;
		return this;
	}
Example #23
0
	public Float2 Add(Float2 xx){
		x+=xx.x;
		y+=xx.y;
		return this;
	}
Example #24
0
	public Float2 Mul(Float2 xx){
		x*=xx.x;
		y*=xx.y;
		return this;
	}
Example #25
0
        public void TracePhoton(ref Photon photon, PhotonMap photonMap, PhotonReflection type)
        {
            bool   wasReflection        = false;
            bool   wasCausticReflection = false;
            Random rnd = new Random();

            for (int i = 0; i < maxReflections; i++)
            {
                Ray ray = new Ray(new Vector3(photon.position[0], photon.position[1], photon.position[2]), new Vector3(photon.direction[0], photon.direction[1], photon.direction[2]));
                //cout << "pozycja " << ray.Origin() << endl;
                //cout << "kierunek " << ray.Direction() << endl;
                int    index    = -1;
                int    j        = -1;
                double distance = 1000;
                bool   wasHit   = false;
                foreach (Mesh mezh in meshes)
                {
                    j++;

                    if (mezh.Intersect(ref ray))
                    {
                        wasHit = true;
                    }
                }
                if (!wasHit)
                {
                    break;
                }
                Mesh    mesh   = meshes[index];
                Vector3 inter  = mesh.IntersectV(ref ray);
                Vector3 normal = mesh.getNormal(ray, distance, inter);
                Color   baze   = new Color();
                if (mesh.faces[0].GetTriangle().GetMaterial() != null)
                {
                    Float2 coords = mesh.getUVCoords(normal, inter);
                    baze = mesh.faces[0].GetTriangle().GetMaterial().diffuseColor;
                }
                else
                {
                    baze = mesh.faces[0].GetTriangle().GetMaterial().diffuseColor;
                }
                float avgColor = (float)((baze.Red() + baze.Green() + baze.Blue()) / 3.0);
                float newRed   = (float)(photon.energy[0] * baze.Red() / avgColor);
                float newBlue  = (float)(photon.energy[1] * baze.Blue() / avgColor);
                float newGreen = (float)(photon.energy[2] * baze.Green() / avgColor);
                if (mesh.faces[0].GetTriangle().GetMaterial() != null)
                {
                    if (!wasCausticReflection && type == PhotonReflection.caustic)
                    {
                        break;
                    }
                    photon.position[0] = inter.x;
                    photon.position[1] = inter.y;
                    photon.position[2] = inter.z;
                    int probability = rnd.Next() % 100;                    //prawdopodobienstwo odbicia
                    if (probability < 40)
                    {
                        photonMap.AddPhoton(ref photon);
                        break;
                    }
                    else
                    {
                        //	cout << "odbicie\n";
                        //wasReflection = true;
                        float[] tab = new float[3];
                        do
                        {
                            tab[0] = (float)((rnd.Next() % 10000 - 5000.0) / 5000.0);
                            tab[1] = (float)((rnd.Next() % 10000 - 5000.0) / 5000.0);
                            tab[2] = (float)((rnd.Next() % 10000 - 5000.0) / 5000.0);
                        } while (tab[0] * tab[0] + tab[1] * tab[1] + tab[2] * tab[2] > 1);
                        for (int m = 0; m < 3; m++)
                        {
                            photon.direction[m] = tab[m];
                        }
                        if (!wasCausticReflection && type == PhotonReflection.caustic)
                        {
                            photon.energy[0] = newRed;
                            photon.energy[1] = newGreen;
                            photon.energy[2] = newBlue;
                            continue;
                        }
                        else
                        {
                            photonMap.AddPhoton(ref photon);
                            photon.energy[0] = newRed;
                            photon.energy[1] = newGreen;
                            photon.energy[2] = newBlue;
                        }
                    }
                }
                else
                {
                    wasReflection        = true;
                    wasCausticReflection = true;
                    Ray topoint   = new Ray(new Vector3(photon.position[0], photon.position[1], photon.position[2]), inter);
                    Ray FromPoint = new Ray();
                    if (mesh.faces[0].GetTriangle().GetMaterial().mirror > 0)
                    {
                        FromPoint = mesh.faces[0].GetTriangle().GetMaterial().MirrorRay(ref topoint, ref normal, ref inter);
                    }
                    else if (mesh.faces[0].GetTriangle().GetMaterial().refractive > 0)
                    {
                        FromPoint = mesh.faces[0].GetTriangle().GetMaterial().RefractRay(ref topoint, ref normal, ref inter, false);
                    }
                    photon.position[0] = inter.x;
                    photon.position[1] = inter.y;
                    photon.position[2] = inter.z;
                    Vector3 dir = FromPoint.Direction;
                    dir.GetNormalized();
                    photon.direction[0] = dir.x;
                    photon.direction[1] = dir.y;
                    photon.direction[2] = dir.z;
                    photon.energy[0]    = newRed;
                    photon.energy[1]    = newGreen;
                    photon.energy[2]    = newBlue;
                    //	cout << "zmienil sie kierunek photonu na " << photon.direction << endl;
                }
            }
        }
Example #26
0
        /// <inheritdoc />
        public override void OnMouseEnter(Float2 location)
        {
            MousePosition = location;

            base.OnMouseEnter(location);
        }
Example #27
0
 public bool Contains(Float2 p)
 {
     return((((this.Left <= p.X) && (this.Right >= p.X)) && (this.Top <= p.Y)) && (this.Bottom >= p.Y));
 }
Example #28
0
 /// <inheritdoc />
 public override bool OnShowTooltip(out string text, out Float2 location, out Rectangle area)
 {
     // Don't show tooltip is user is moving the stop
     return(base.OnShowTooltip(out text, out location, out area) && !_isMoving);
 }
Example #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VisjectCM"/> class.
        /// </summary>
        /// <param name="info">The initialization info data.</param>
        public VisjectCM(InitInfo info)
        {
            if (info.Groups == null)
            {
                throw new ArgumentNullException(nameof(info.Groups));
            }
            if (info.CanSpawnNode == null)
            {
                throw new ArgumentNullException(nameof(info.CanSpawnNode));
            }
            _parametersGetter          = info.ParametersGetter;
            _parameterGetNodeArchetype = info.ParameterGetNodeArchetype ?? Archetypes.Parameters.Nodes[0];
            if (info.CanSetParameters)
            {
                _parameterSetNodeArchetype = info.ParameterSetNodeArchetype ?? Archetypes.Parameters.Nodes[3];
            }

            // Context menu dimensions
            Size = new Float2(320, 220);

            // Search box
            _searchBox = new TextBox(false, 1, 1)
            {
                Width         = Width - 3,
                WatermarkText = "Search...",
                Parent        = this
            };
            _searchBox.TextChanged += OnSearchFilterChanged;

            // Create first panel (for scrollbar)
            var panel1 = new Panel(ScrollBars.Vertical)
            {
                Bounds = new Rectangle(0, _searchBox.Bottom + 1, Width, Height - _searchBox.Bottom - 2),
                Parent = this
            };

            _panel1 = panel1;

            // Create second panel (for groups arrangement)
            var panel2 = new VerticalPanel
            {
                Parent       = panel1,
                AnchorPreset = AnchorPresets.HorizontalStretchTop,
                IsScrollable = true,
            };

            _groupsPanel = panel2;

            // Init groups
            var nodes = new List <NodeArchetype>();

            foreach (var groupArchetype in info.Groups)
            {
                // Get valid nodes
                nodes.Clear();
                foreach (var nodeArchetype in groupArchetype.Archetypes)
                {
                    if ((nodeArchetype.Flags & NodeFlags.NoSpawnViaGUI) == 0 && info.CanSpawnNode(nodeArchetype))
                    {
                        nodes.Add(nodeArchetype);
                    }
                }

                // Check if can create group for them
                if (nodes.Count > 0)
                {
                    var group = new VisjectCMGroup(this, groupArchetype)
                    {
                        HeaderText = groupArchetype.Name
                    };

                    group.Close(false);
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        var item = new VisjectCMItem(group, groupArchetype, nodes[i])
                        {
                            Parent = group
                        };
                    }
                    group.SortChildren();
                    group.Parent = panel2;

                    _groups.Add(group);
                }
            }

            // Add custom nodes (special handling)
            if (info.CustomNodesGroup?.Archetypes != null)
            {
                foreach (var nodeArchetype in info.CustomNodesGroup.Archetypes)
                {
                    if ((nodeArchetype.Flags & NodeFlags.NoSpawnViaGUI) != 0)
                    {
                        continue;
                    }

                    var groupName = Archetypes.Custom.GetNodeGroup(nodeArchetype);

                    // Find group to reuse
                    VisjectCMGroup group = null;
                    for (int j = 0; j < _groups.Count; j++)
                    {
                        if (string.Equals(_groups[j].Archetype.Name, groupName, StringComparison.OrdinalIgnoreCase))
                        {
                            group = _groups[j];
                            break;
                        }
                    }

                    // Create new group if name is unique
                    if (group == null)
                    {
                        group = new VisjectCMGroup(this, info.CustomNodesGroup)
                        {
                            HeaderText = groupName
                        };

                        group.Close(false);
                        group.Parent = _groupsPanel;
                        _groups.Add(group);
                    }

                    // Add new item
                    var item = new VisjectCMItem(group, info.CustomNodesGroup, nodeArchetype)
                    {
                        Parent = group
                    };

                    // Order items
                    group.SortChildren();
                }
            }
        }
Example #30
0
 /// <inheritdoc />
 public override bool OnTestTooltipOverControl(ref Float2 location)
 {
     // Don't show tooltip is user is moving the stop
     return(base.OnTestTooltipOverControl(ref location) && !_isMoving);
 }
Example #31
0
Float DotNoise(Float X,Float Y,Float Val1,Float Val2,Float Val3)
{
	Float3 Rad = new Float3(Val1,Val2,Val3);
	Float2 P = new Float2(X,Y);
	Float radius_low = Rad.x;
	Float radius_high = Rad.y;
	Float2 Pi = floor(P,true);
	Float2 Pf = P-Pi;

	Float4 Hash = FastHash2D(Pi);
	
	Float Radius = max(0.0f,radius_low+Hash.z*(radius_high-radius_low),true);
	Float Value = Radius/max(radius_high,radius_low,true);
	
	Radius = 2.0f/Radius;
	Pf *= Radius;
	Pf -= (Radius - 1.0f);
	Pf += Hash.xy*(Radius - 2f);
	Pf = pow(Pf,Rad.z);
	return DotFalloff(min(dot(Pf,Pf),1.0f,true))*Value;
}
Example #32
0
		private IMeshStream CreateMeshStream(ISource source, string semantic)
		{
			var floatArray = source as FloatArraySource;
			if (floatArray != null)
			{
				bool swapY = (semantic == Streams.TexCoord);
				if (source.GetStride() == 3)
				{
					var arrayMeshStream = new ArrayMeshStream<Float3>(source.GetCount(), streamConverterFactory);
					for (int i = 0; i < arrayMeshStream.Count; ++i)
					{
						var y = floatArray[i * 3 + 1];
						if (swapY) y = 1.0f - y;
						arrayMeshStream[i] = new Float3(floatArray[i * 3 + 0], y, floatArray[i * 3 + 2]);
					}
					return arrayMeshStream;
				}
				else if (source.GetStride() == 2)
				{
					var arrayMeshStream = new ArrayMeshStream<Float2>(source.GetCount(), streamConverterFactory);
					for (int i = 0; i < arrayMeshStream.Count; ++i)
					{
						var y = floatArray[i * 2 + 1];
						if (swapY) y = 1.0f - y;
						arrayMeshStream[i] = new Float2(floatArray[i * 2 + 0], y);
					}
					return arrayMeshStream;
				}
				else if (source.GetStride() == 4)
				{
					var arrayMeshStream = new ArrayMeshStream<Float4>(source.GetCount(), streamConverterFactory);
					for (int i = 0; i < arrayMeshStream.Count; ++i)
					{
						var y = floatArray[i * 4 + 1];
						if (swapY) y = 1.0f - y;
						arrayMeshStream[i] = new Float4(floatArray[i * 4 + 0], y, floatArray[i * 4 + 2], floatArray[i * 4 + 3]);
					}
					return arrayMeshStream;
				}
			}
			else
			{
				throw new NotImplementedException();
			}
			throw new NotImplementedException();
		}
Example #33
0
 public static void Clip(Float2 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float2)})");
Example #34
0
        public static Float3 getBarycentricCoordinates(Float2 t1, Float2 t2, Float2 t3, Float2 p)
        {
            float T  = Utils.getTriangleArea(t1, t2, t3);
            float T1 = Utils.getTriangleArea(t2, t3, p);
            float T2 = Utils.getTriangleArea(t1, p, t3);
            float T3 = Utils.getTriangleArea(t1, t2, p);

            return(new Float3(T1 / T, T2 / T, T3 / T));
        }
Example #35
0
 public Float3(Float2 xy, float z)
 {
     this.X = xy.X;
     this.Y = xy.Y;
     this.Z = z;
 }
Example #36
0
 public static float getTriangleAreaHeron(Float2 t1, Float2 t2, Float2 t3)
 {
     return(getPerimeter(t1, t2, t3) / 2.0f);
 }
Example #37
0
        public static Float3x3 Perspective(float x, float y, float width, float height, Float2 t1, Float2 t2, Float2 t3, Float2 t4)
        {
            var scalex = 1.0f;
            var scaley = 1.0f;

            if (width > 0)
            {
                scalex = 1.0f / width;
            }

            if (height > 0)
            {
                scaley = 1.0f / height;
            }

            var matrix = Float3x3.Identity;

            matrix = matrix.Translate(-x, -y);
            matrix = matrix.Scale(scalex, scaley);

            var trafo = new Float3x3();

            {
                var t_x1 = t1.X;
                var t_y1 = t1.Y;
                var t_x2 = t2.X;
                var t_y2 = t2.Y;
                var t_x3 = t3.X;
                var t_y3 = t3.Y;
                var t_x4 = t4.X;
                var t_y4 = t4.Y;
                var dx1  = t_x2 - t_x4;
                var dx2  = t_x3 - t_x4;
                var dx3  = t_x1 - t_x2 + t_x4 - t_x3;
                var dy1  = t_y2 - t_y4;
                var dy2  = t_y3 - t_y4;
                var dy3  = t_y1 - t_y2 + t_y4 - t_y3;
                /*  Is the mapping affine?  */
                var epsilon = 1e-4f;
                if ((dx3.EpsilonEquals(0, epsilon)) && (dy3.EpsilonEquals(0, epsilon)))
                {
                    trafo.coeff[0][0] = t_x2 - t_x1;
                    trafo.coeff[0][1] = t_x4 - t_x2;
                    trafo.coeff[0][2] = t_x1;
                    trafo.coeff[1][0] = t_y2 - t_y1;
                    trafo.coeff[1][1] = t_y4 - t_y2;
                    trafo.coeff[1][2] = t_y1;
                    trafo.coeff[2][0] = 0.0f;
                    trafo.coeff[2][1] = 0.0f;
                }
                else
                {
                    var det1 = dx3 * dy2 - dy3 * dx2;
                    var det2 = dx1 * dy2 - dy1 * dx2;

                    trafo.coeff[2][0] = det2.EpsilonEquals(0, epsilon) ? 1.0f : det1 / det2;

                    det1 = dx1 * dy3 - dy1 * dx3;

                    trafo.coeff[2][1] = det2.EpsilonEquals(0, epsilon) ? 1.0f : det1 / det2;

                    trafo.coeff[0][0] = t_x2 - t_x1 + trafo.coeff[2][0] * t_x2;
                    trafo.coeff[0][1] = t_x3 - t_x1 + trafo.coeff[2][1] * t_x3;
                    trafo.coeff[0][2] = t_x1;

                    trafo.coeff[1][0] = t_y2 - t_y1 + trafo.coeff[2][0] * t_y2;
                    trafo.coeff[1][1] = t_y3 - t_y1 + trafo.coeff[2][1] * t_y3;
                    trafo.coeff[1][2] = t_y1;
                }
                trafo.coeff[2][2] = 1.0f;
            }

            return(trafo.Multiply(matrix));
        }
Example #38
0
 public void Uniform2(int location, Float2 value)
 {
     TKGL.Uniform2(location, value.X, value.Y);
 }
 public Vertex(Float3 position, Float4 color, Float3 normal, Float2 uv1)
     : this(position, color, normal, uv1, uv2 : Float2.Zero)
 {
 }
Example #40
0
public Float2 max(Float2 s,Float2 ss,bool SpawnNew){
	if (SpawnNew){
	s = new Float2(s.x,s.y);
	ss = new Float2(ss.x,ss.y);
	}
	s.x = Mathf.Max(s.x,ss.x);
	s.y = Mathf.Max(s.y,ss.y);
	return s;
}
 public static void elDrawLine(this Bitmap b, Float2 v0, Float2 v1, Color color)
 {
     b.elDrawLine(v0.x, v0.y, v1.x, v1.y, color);
 }
        private Mesh ParseGeometry(XmlElement geometryElement, Float4x4 transform)
        {
            XmlElement meshElement = geometryElement.GetChild("mesh");

            if (meshElement == null)
            {
                throw new Exception($"[{nameof(ColladaParser)}] Mesh element missing");
            }

            //Parse the triangles
            ParseTriangles(meshElement);

            //Parse input data
            int minTexcoordSet = GetMinSet("TEXCOORD");

            for (int i = 0; i < inputs.Count; i++)
            {
                Input      input       = inputs.Data[i];
                XmlElement dataElement = meshElement.GetChildWithAttribute(
                    name: "source",
                    attributeName: "id",
                    attributeValue: input.Source);
                switch (input.Semantic)
                {
                case "POSITION": ParseFloatSetArray(dataElement, positions); break;

                case "COLOR": ParseFloatSetArray(dataElement, colors); break;

                case "NORMAL": ParseFloatSetArray(dataElement, normals); break;

                case "TEXCOORD":
                    if (input.Set == minTexcoordSet)
                    {
                        ParseFloatSetArray(dataElement, texcoords1);
                    }
                    else
                    if (input.Set == minTexcoordSet + 1)
                    {
                        ParseFloatSetArray(dataElement, texcoords2);
                    }
                    break;
                }
            }

            //Build a mesh from the parsed data
            MeshBuilder meshBuilder = new MeshBuilder();

            for (int i = 0; i < triangleCount; i++)
            {
                //Surface normal is used when a vertex doesn't specify explict normals
                Float3 surfaceNormal = Triangle.GetNormal(
                    GetPosition(i, vertexIndex: 2),
                    GetPosition(i, vertexIndex: 1),
                    GetPosition(i, vertexIndex: 0));

                //In reverse as collada uses counter-clockwise triangles and we use clockwise
                for (int j = 3 - 1; j >= 0; j--)
                {
                    Float3 position = GetPosition(i, vertexIndex: j);

                    int    colorIndex = GetIndex(i, vertexIndex: j, semantic: "COLOR");
                    Float4 color      = colorIndex < 0 ? Float4.One : colors.Data[colorIndex];

                    int    normalIndex = GetIndex(i, vertexIndex: j, semantic: "NORMAL");
                    Float3 normal      = normalIndex < 0 ?
                                         surfaceNormal :
                                         transform.TransformDirection(Float3.FastNormalize(normals.Data[normalIndex]));

                    int    texcoord1Index = GetIndex(i, vertexIndex: j, semantic: "TEXCOORD", set: minTexcoordSet);
                    Float2 texcoord1      = texcoord1Index < 0 ? Float2.Zero : texcoords1.Data[texcoord1Index];

                    int    texcoord2Index = GetIndex(i, vertexIndex: j, semantic: "TEXCOORD", set: minTexcoordSet + 1);
                    Float2 texcoord2      = texcoord2Index < 0 ? Float2.Zero : texcoords2.Data[texcoord2Index];

                    meshBuilder.PushVertex(new Vertex(
                                               position: position,
                                               color: color,
                                               normal: normal,
                                               //Convert uv to be origin = bottom left
                                               uv1: (texcoord1.X, 1f - texcoord1.Y),
                                               uv2: (texcoord2.X, 1f - texcoord2.Y)));
                }
            }
            return(meshBuilder.ToMesh());

            Float3 GetPosition(int triangleIndex, int vertexIndex)
            {
                int index = GetIndex(triangleIndex, vertexIndex, semantic: "POSITION");

                if (index < 0)
                {
                    throw new Exception(
                              $"[{nameof(ColladaParser)}] No position data found for: triangle: {triangleIndex}, vertex: {vertexIndex}");
                }
                return(transform.TransformPoint(positions.Data[index]));
            }

            int GetIndex(int triangleIndex, int vertexIndex, string semantic, int set = -1)
            {
                int offset = GetOffset(semantic, set);

                if (offset < 0)
                {
                    return(-1);
                }
                int triangleStartOffset = triangleIndex * inputStride * 3;
                int vertexStartOffset   = vertexIndex * inputStride;

                return(indices.Data[triangleStartOffset + vertexStartOffset + offset]);
            }

            int GetOffset(string semantic, int set)
            {
                for (int i = 0; i < inputs.Count; i++)
                {
                    if (inputs.Data[i].Semantic == semantic && inputs.Data[i].Set == set)
                    {
                        return(inputs.Data[i].Offset);
                    }
                }
                //If we don't care about a particular set (set < 0) we take any set that matches
                //the given semantic
                if (set < 0)
                {
                    for (int i = 0; i < inputs.Count; i++)
                    {
                        if (inputs.Data[i].Semantic == semantic)
                        {
                            return(inputs.Data[i].Offset);
                        }
                    }
                }
                return(-1);
            }

            int GetMinSet(string semantic)
            {
                int min = int.MaxValue;

                for (int i = 0; i < inputs.Count; i++)
                {
                    if (inputs.Data[i].Semantic == semantic && inputs.Data[i].Set < min)
                    {
                        min = inputs.Data[i].Set;
                    }
                }
                return(min);
            }
        }
Example #43
0
        public static Rect ContainingPoints(Float2 point0, Float2 point1, Float2 point2, Float2 point3)
        {
            float minX = point0.X;
            float maxX = point0.X;
            float minY = point0.Y;
            float maxY = point0.Y;

            minX = Math.Min(minX, point1.X);
            maxX = Math.Max(maxX, point1.X);
            minY = Math.Min(minY, point1.Y);
            maxY = Math.Max(maxY, point1.Y);
            minX = Math.Min(minX, point2.X);
            maxX = Math.Max(maxX, point2.X);
            minY = Math.Min(minY, point2.Y);
            maxY = Math.Max(maxY, point2.Y);
            minX = Math.Min(minX, point3.X);
            maxX = Math.Max(maxX, point3.X);
            minY = Math.Min(minY, point3.Y);
            maxY = Math.Max(maxY, point3.Y);
            return(new Rect(minX, minY, maxX, maxY));
        }
 /// <inheritdoc/>
 public TPixel this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}[{typeof(Float2)}]");
Example #45
0
 public static Rect Translate(Rect r, Float2 offset)
 {
     return(new Rect(r.Left + offset.X, r.Top + offset.Y, r.Right + offset.X, r.Bottom + offset.Y));
 }
Example #46
0
 /// <inheritdoc />
 public override bool OnMouseUp(Float2 location, MouseButton button)
 {
     Tabs.SelectedTabIndex = Index;
     Tabs.Focus();
     return(true);
 }
Example #47
0
 public static Rect Inflate(Rect r, Float2 size)
 {
     return(new Rect(r.Left - size.X, r.Top - size.Y, r.Right + size.X, r.Bottom + size.Y));
 }
Example #48
0
        public void Update(float dt)
        {
            // Reset deltas
            MovementNormalizedDelta = new Float4(0.0f);
            MovementRawDelta        = new Float4(0.0f);
            MovementDirectDelta     = new Float4(0.0f);
            RotationDelta           = new Float4(0.0f);
            RotationQuaternionDelta = Quaternion.Default;
            ScaleDelta = new Float4(0.0f);
            FovDelta   = 0.0f;
            MovementNormalizedLength = 0.0f;

            if (ActiveMapping != null)
            {
                foreach (var input in ActiveMapping.KeyInputs)
                {
                    if (CheckKeyInput(input.Key, input.Type))
                    {
                        // Skip single keys if there is a combo key input active
                        bool skipKey = false;
                        foreach (var comboKeyInput in ActiveMapping.ComboKeyInputs.Where(x => x.ConsumeInput && (x.Key1 == input.Key || x.Key2 == input.Key)))
                        {
                            var key  = comboKeyInput.Key1 == input.Key ? comboKeyInput.Key2 : comboKeyInput.Key1;
                            var type = comboKeyInput.Key1 == input.Key ? comboKeyInput.Type2 : comboKeyInput.Type1;
                            if (CheckKeyInput(key, type))
                            {
                                skipKey = true;
                                break;
                            }
                        }

                        if (skipKey)
                        {
                            continue;
                        }

                        input.Action.Execute();
                    }
                }

                foreach (var input in ActiveMapping.ComboKeyInputs)
                {
                    if (CheckKeyInput(input.Key1, input.Type1) && CheckKeyInput(input.Key2, input.Type2))
                    {
                        input.Action.Execute();
                    }
                }

                foreach (var input in ActiveMapping.MouseInputs)
                {
                    if (CheckMouseInput(input.Key, input.Type))
                    {
                        input.Action.Execute();
                    }
                }

                foreach (var input in ActiveMapping.ScrollInputs)
                {
                    if (CheckScrollInput(input.Key))
                    {
                        input.Action.Execute();
                    }
                }

                if (CaptureMouse)
                {
                    Float2 mouseDiff = Application.GetCursorDiff(true);

                    foreach (var input in ActiveMapping.MouseAxisInputs)
                    {
                        float length = input.Axis.Dot(mouseDiff);
                        if (Math.Abs(length) > Constants.Epsilon)
                        {
                            if (input.Action is InputMovementAction movementAction)
                            {
                                // Copy of the InputMovementAction.Execute function but multiplied with length for mouse input
                                var vector = movementAction.GetVector() * length;
                                MovementRawDelta += vector;
                                if (movementAction.Normalize)
                                {
                                    MovementNormalizedLength = Math.Max(vector.Length(), MovementNormalizedLength);
                                }
                                else
                                {
                                    MovementDirectDelta += vector;
                                }
                            }
                            else if (input.Action is InputRotationAction rotationAction)
                            {
                                RotationDelta += rotationAction.GetRotation() * length;
                                // TODO: move dt to UpdateEntities
                                RotationQuaternionDelta *= rotationAction.GetQuaternion(length * dt);
                            }
                            else if (input.Action is InputScalingAction scaleAction)
                            {
                                ScaleDelta += scaleAction.GetVector() * length;
                            }
                            else
                            {
                                input.Action.Execute();
                            }
                        }
                    }
                }
            }

            MovementNormalizedDelta += MovementRawDelta.Normalize() * MovementNormalizedLength;

            UpdateEntities(dt);
        }
Example #49
0
 /// <inheritdoc />
 public override void Show(Control parent, Float2 location)
 {
     Show(parent, location, null);
 }
Example #50
0
 /// <summary>
 /// Writes the Vector2 to the binary stream.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="value">The value to write.</param>
 public static void Write(this BinaryWriter stream, Float2 value)
 {
     stream.Write(value.X);
     stream.Write(value.Y);
 }
Example #51
0
public Float2 floor(Float2 s,bool SpawnNew){
	if (SpawnNew)
		s = new Float2(s.x,s.y);
	s.x = Mathf.Floor(s.x);
	s.y = Mathf.Floor(s.y);
	return s;
}
Example #52
-1
Float4 FastHash2D(Float2 Pos){
	Float2 Offset = new Float2(26,161);
	Float Domain = 71;
	Float SomeLargeFloat = 951.135664f;
	Float4 P = new Float4(Pos.xy,Pos.xy+1);
	//P = P-floor(P*(1.0f/Domain))*Domain;
	P = P-floor((P+0).Mul(1.0f/Domain),true).Mul(Domain);
	P.Add(Offset.xyxy);
	P.Square();
	return frac(P.xzxz.Mul(P.yyww).Mul(1.0f/SomeLargeFloat),false);
}