Example #1
0
 public unsafe static void SetPointInWorld(this PointCollector obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.PointInWorld = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
Example #2
0
 private void editorY_Edited(object sender, EventArgs e)
 {
     if (this.IsUpdating)
     {
         return;
     }
     if (this.Disposed)
     {
         return;
     }
     if (!this.ReadOnly)
     {
         object[] values = this.GetValue().ToArray();
         Vector3  newVal = (Vector3)this.DisplayedValue;
         for (int i = 0; i < values.Length; i++)
         {
             if (values[i] == null)
             {
                 values[i] = this.DisplayedValue;
             }
             else
             {
                 Vector3 oldVal = (Vector3)values[i];
                 values[i] = new Vector3(oldVal.X, newVal.Y, oldVal.Z);
             }
         }
         this.SetValues(values);
     }
     this.PerformGetValue();
 }
Example #3
0
 public unsafe static void GetAxis1(this Hinge2Constraint obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.Axis1;
     }
 }
Example #4
0
        private void SimpleCamera(OpenTK.Vector3 average_point)
        {
            {
                const float    yFov         = 1.00899694f; // 75
                const float    near         = 100;
                const float    far          = 7000;
                float          aspect_ratio = GLControl.Width / GLControl.Height;
                OpenTK.Matrix4 projection;
                projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(yFov, aspect_ratio, near, far);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();
                GL.LoadMatrix(ref projection);
            }

            {
                const float    eye_height = 5000;
                OpenTK.Matrix4 lookat;
                lookat = OpenTK.Matrix4.LookAt(0.0f, eye_height, 0.0f,
                                               average_point.X, average_point.Y, average_point.Z,
                                               0.0f, 0.0f, 1.0f);

                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.LoadMatrix(ref lookat);
            }
        }
Example #5
0
 public unsafe static void SetInvInertiaDiagLocal(this RigidBody obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.InvInertiaDiagLocal = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
Example #6
0
 public unsafe static void SetMassProps(this RigidBody obj, float mass, ref OpenTK.Vector3 inertia)
 {
     fixed(OpenTK.Vector3 *inertiaPtr = &inertia)
     {
         obj.SetMassProps(mass, ref *(BulletSharp.Math.Vector3 *)inertiaPtr);
     }
 }
Example #7
0
 public unsafe static void GetCenterOfMassPosition(this RigidBody obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.CenterOfMassPosition;
     }
 }
Example #8
0
 public unsafe static void GetTotalTorque(this RigidBody obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.TotalTorque;
     }
 }
Example #9
0
        /// <summary>
        /// Draws the twist constraints accoriding in Unity using Giszmos
        /// </summary>
        /// <param name="b">The bone with its constraints</param>
        /// <param name="refBone">The to be twisted against</param>
        /// <param name="poss">The position of where it should be drawn</param>
        /// <param name="scale">The scale of the constraints</param>
        public static void DrawTwistConstraints(Bone b, Bone refBone, OpenTK.Vector3 poss, float scale)
        {
            if (b.Orientation.Xyz.IsNaN() || refBone.Orientation.Xyz.IsNaN())
            {
                return;
            }
            OpenTK.Vector3 thisY = b.GetYAxis();

            OpenTK.Quaternion referenceRotation = refBone.Orientation * b.ParentPointer;
            OpenTK.Vector3    parentY           = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitY, referenceRotation);
            OpenTK.Vector3    parentZ           = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitZ, referenceRotation);

            OpenTK.Quaternion rot       = QuaternionHelper2.GetRotationBetween(parentY, thisY);
            OpenTK.Vector3    reference = OpenTK.Vector3.Transform(parentZ, rot);
            reference.Normalize();
            Debug.DrawRay(poss.Convert(), (b.GetZAxis() * scale * 2).Convert(), Color.cyan);


            float startTwistLimit = OpenTK.MathHelper.DegreesToRadians(b.StartTwistLimit);

            OpenTK.Vector3 m = OpenTK.Vector3.Transform(reference, OpenTK.Quaternion.FromAxisAngle(thisY, startTwistLimit));
            m.Normalize();
            Debug.DrawRay(poss.Convert(), m.Convert() * scale, Color.yellow);

            float endTwistLimit = OpenTK.MathHelper.DegreesToRadians(b.EndTwistLimit);

            OpenTK.Vector3 m2 = OpenTK.Vector3.Transform(reference, OpenTK.Quaternion.FromAxisAngle(thisY, endTwistLimit));
            m2.Normalize();
            Debug.DrawRay(poss.Convert(), m2.Convert() * scale, Color.magenta);

            Debug.DrawLine((poss + (m * scale)).Convert(), (poss + (m2 * scale)).Convert(), Color.cyan);
        }
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Name           = binaryReader.ReadStringID();
     this.Position       = binaryReader.ReadVector3();
     this.ReferenceFrame = binaryReader.ReadInt16();
     this.fieldpad       = binaryReader.ReadBytes(2);
     this.Facing         = binaryReader.ReadVector2();
     this.ActorStartingLocationsFlags = ((Flags)(binaryReader.ReadInt32()));
     this.CharacterType          = binaryReader.ReadShortBlockIndex1();
     this.InitialWeapon          = binaryReader.ReadShortBlockIndex1();
     this.InitialSecondaryWeapon = binaryReader.ReadShortBlockIndex1();
     this.fieldpad0               = binaryReader.ReadBytes(2);
     this.VehicleType             = binaryReader.ReadShortBlockIndex1();
     this.SeatType                = ((SeatTypeEnum)(binaryReader.ReadInt16()));
     this.GrenadeType             = ((GrenadeTypeEnum)(binaryReader.ReadInt16()));
     this.SwarmCount              = binaryReader.ReadInt16();
     this.ActorVariantName        = binaryReader.ReadStringID();
     this.VehicleVariantName      = binaryReader.ReadStringID();
     this.InitialMovementDistance = binaryReader.ReadSingle();
     this.EmitterVehicle          = binaryReader.ReadShortBlockIndex1();
     this.InitialMovementMode     = ((InitialMovementModeEnum)(binaryReader.ReadInt16()));
     this.PlacementScript         = binaryReader.ReadString32();
     this.fieldskip               = binaryReader.ReadBytes(2);
     this.fieldpad1               = binaryReader.ReadBytes(2);
     return(pointerQueue);
 }
 public unsafe static void SetLocalScaling(this CollisionShape obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.LocalScaling = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
Example #12
0
        public GFLXBone(GFLXModel parent, Bone bone) : base(parent.Skeleton)
        {
            ParentModel = parent;
            Bone        = bone;

            Text        = bone.Name;
            parentIndex = bone.Parent;

            if (bone.Translation != null)
            {
                Position = new OpenTK.Vector3(
                    bone.Translation.X,
                    bone.Translation.Y,
                    bone.Translation.Z
                    );
            }

            if (bone.Rotation != null)
            {
                EulerRotation = new OpenTK.Vector3(
                    bone.Rotation.X,
                    bone.Rotation.Y,
                    bone.Rotation.Z
                    );
            }

            if (bone.Scale != null)
            {
                Scale = new OpenTK.Vector3(
                    bone.Scale.X,
                    bone.Scale.Y,
                    bone.Scale.Z
                    );
            }
        }
 public unsafe static void GetLocalScaling(this CollisionShape obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.LocalScaling;
     }
 }
 public unsafe static void GetBoundingSphere(this CollisionShape obj, out OpenTK.Vector3 center, out float radius)
 {
     fixed(OpenTK.Vector3 *centerPtr = &center)
     {
         obj.GetBoundingSphere(out *(BulletSharp.Math.Vector3 *)centerPtr, out radius);
     }
 }
 public unsafe static void GetAnchor(this UniversalConstraint obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.Anchor;
     }
 }
Example #16
0
 public unsafe static void SetAppliedTorqueBodyA(this JointFeedback obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.AppliedTorqueBodyA = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
        public OpenTK.Vector3 FullWidthVector3Input(OpenTK.Vector3 vec, string name,
                                                    float increment = 1, int incrementDragDivider = 8, float min = float.MinValue, float max = float.MaxValue, bool wrapAround = false)
        {
            currentY += beforeTwoLineSpacing;

            NumberInputInfo input = new NumberInputInfo(increment, incrementDragDivider, min, max, wrapAround);

            const int nameWidth = 13;
            int       width     = (usableWidth - margin * 2 - fullWidthSpace * 2) / 3;

            g.DrawString(name, HeadingFont, SystemBrushes.ControlText, margin, currentY);
            currentY += rowHeight;

            DrawText(margin, currentY, "X");
            vec.X = NumericInputField(margin + nameWidth, currentY, width - nameWidth, vec.X, input, true);

            DrawText(10 + width + fullWidthSpace, currentY, "Y");
            vec.Y = NumericInputField(margin + nameWidth + width + fullWidthSpace, currentY, width - nameWidth, vec.Y, input, true);

            DrawText(10 + width * 2 + fullWidthSpace * 2, currentY, "Z");
            vec.Z = NumericInputField(margin + nameWidth + width * 2 + fullWidthSpace * 2, currentY, width - nameWidth, vec.Z, input, true);


            currentY += rowHeight;
            return(vec);
        }
        public Model Generate()
        {
            int count = 1000;
            Vector3[] v = new Vector3[count];
            Vector3[] r = new Vector3[count];
            Random random = new Random();
            Color[] color = new Color[count];
            float[] m = new float[count];

            v[0] = new Vector3(0,
                    0,
                    0);
            r[0] = new Vector3(0,
                0,
                0);
            m[0] = 1000000000;
            color[0] = Color.white;

            for (int i = 1; i < count; i++)
            {
                v[i] = new Vector3((float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1),
                    (float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1),
                    (float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1));
                r[i] = new Vector3((float)random.NextDouble() * 100,
                    (float)random.NextDouble() * 100,
                    (float)random.NextDouble() * 100);
                m[i] = random.Next(10000, 100000);
                color[i] = Color.yellow;
            }
            Model model = new Model(r, v, m, color);
            model.G = 0.00001f;
            model.dt = 0.005f;
            return model;
        }
Example #19
0
 public unsafe static void GetPlaneNormal(this StaticPlaneShape obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.PlaneNormal;
     }
 }
Example #20
0
 public unsafe static void ApplyTorqueImpulse(this RigidBody obj, ref OpenTK.Vector3 torque)
 {
     fixed(OpenTK.Vector3 *torquePtr = &torque)
     {
         obj.ApplyTorqueImpulse(ref *(BulletSharp.Math.Vector3 *)torquePtr);
     }
 }
Example #21
0
		/// <summary>
		/// Read ZY-YZ reversed vector<para/>
		/// Чтение перевернутого ZY-YZ вектора
		/// </summary>
		/// <returns>Correct vector<para/>Исправленный вектор</returns>
		public static OpenTK.Vector3 ReadVCVector(this BinaryReader f) {
			OpenTK.Vector3 v = new OpenTK.Vector3();
			v.X = f.ReadSingle();
			v.Z = f.ReadSingle();
			v.Y = f.ReadSingle();
			return v;
		}
Example #22
0
 public unsafe static void GetLinearVelocity(this RigidBody obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.LinearVelocity;
     }
 }
 public unsafe static void SetCachedSeparatingAxis(this GjkPairDetector obj, ref OpenTK.Vector3 seperatingAxis)
 {
     fixed(OpenTK.Vector3 *seperatingAxisPtr = &seperatingAxis)
     {
         obj.CachedSeparatingAxis = *(BulletSharp.Math.Vector3 *)seperatingAxisPtr;
     }
 }
Example #24
0
 public unsafe static void SetAngularFactor(this RigidBody obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.AngularFactor = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
 public unsafe static void GetCachedSeparatingAxis(this GjkPairDetector obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.CachedSeparatingAxis;
     }
 }
Example #26
0
 public unsafe static void SetLinearVelocity(this RigidBody obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.LinearVelocity = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
Example #27
0
 public unsafe static int FindOrAddVertex(this TriangleMesh obj, ref OpenTK.Vector3 vertex, bool removeDuplicateVertices)
 {
     fixed(OpenTK.Vector3 *vertexPtr = &vertex)
     {
         return(obj.FindOrAddVertex(ref *(BulletSharp.Math.Vector3 *)vertexPtr, removeDuplicateVertices));
     }
 }
Example #28
0
 public unsafe static void Translate(this RigidBody obj, ref OpenTK.Vector3 v)
 {
     fixed(OpenTK.Vector3 *vPtr = &v)
     {
         obj.Translate(ref *(BulletSharp.Math.Vector3 *)vPtr);
     }
 }
Example #29
0
        public static void GenerateFace(List <Vector3> Verts, List <Vector2> UVs, List <INDEX_TYPE> TexIDs, INDEX_TYPE TexID,
                                        //Vector3 Normal,
                                        Vector3 A, Vector2 UVA,
                                        Vector3 B, Vector2 UVB,
                                        Vector3 C, Vector2 UVC,
                                        Vector3 D, Vector2 UVD)
        {
            for (int i = 0; i < 6; i++)
            {
                //Norms.Add(Normal);
                TexIDs.Add(TexID);
            }

            Verts.Add(A);
            Verts.Add(B);
            Verts.Add(C);
            Verts.Add(A);
            Verts.Add(C);
            Verts.Add(D);

            UVs.Add(UVA);
            UVs.Add(UVB);
            UVs.Add(UVC);
            UVs.Add(UVA);
            UVs.Add(UVC);
            UVs.Add(UVD);
        }
Example #30
0
 public unsafe static void ApplyCentralImpulse(this RigidBody obj, ref OpenTK.Vector3 impulse)
 {
     fixed(OpenTK.Vector3 *impulsePtr = &impulse)
     {
         obj.ApplyCentralImpulse(ref *(BulletSharp.Math.Vector3 *)impulsePtr);
     }
 }
Example #31
0
 public unsafe static void GetNormalOnBInWorld(this PointCollector obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.NormalOnBInWorld;
     }
 }
Example #32
0
 public unsafe static void ApplyCentralForce(this RigidBody obj, ref OpenTK.Vector3 force)
 {
     fixed(OpenTK.Vector3 *forcePtr = &force)
     {
         obj.ApplyCentralForce(ref *(BulletSharp.Math.Vector3 *)forcePtr);
     }
 }
Example #33
0
 public Vertex3f(Vertex3f that)
     : this(that.x, that.y, that.z)
 {
     if (that.normal != null)
     {
         this.normal = new OpenTK.Vector3(that.normal.X, that.normal.Y, that.normal.Z);
     }
 }
Example #34
0
 public npc(OpenTK.Vector3 pos, OpenTK.Vector2 dim, string textpath)
     : base(pos, dim, textpath, 250.0f)
 {
     interacting = false;
     rand = new Random();
     counter = 0;
     a = rand.Next(0, 100);
     Centerpoint = new OpenTK.Vector3(pos.X + dim.X / 2, pos.Y - dim.Y / 2, 0);
     //direction = new OpenTK.Vector2(0.0005f, 0.0005f);
 }
        public void CanConvertOpenTKVectorToNumericVector()
        {
            float x = _fixture.Create<float>();
            float y = _fixture.Create<float>();
            float z = _fixture.Create<float>();

            OpenTK.Vector3 openTKVector = new OpenTK.Vector3(x, y, z);
            Vector3 vector = openTKVector.ToNumericVector();

            Assert.That(vector, Is.Not.Null);
            Assert.That(vector.X, Is.EqualTo(openTKVector.X));
            Assert.That(vector.Y, Is.EqualTo(openTKVector.Y));
            Assert.That(vector.Z, Is.EqualTo(openTKVector.Z));
        }
Example #36
0
		public static void drawLine( Display render, ref Vector3 from, ref Vector3 to, ref Vector3 fromColor, ref Vector3 toColor )
		{
			OpenTK.Vector3[] v = new OpenTK.Vector3[2];
			OpenTK.Vector4 c;
			OpenTK.Vector4 c2;
			c.X = fromColor.X;
			c.Y = fromColor.Y;
			c.Z = fromColor.Z;
			c.W = 1;
			c2.X = toColor.X;
			c2.Y = toColor.Y;
			c2.Z = toColor.Z;
			c2.W = 1;
			v[0].X = from.X;
			v[0].Y = from.Y;
			v[0].Z = from.Z;
			v[1].X = to.X;
			v[1].Y = to.Y;
			v[1].Z = to.Z;
			geometry.AddLine( v, ref c );
		}
		private void editorX_Edited(object sender, EventArgs e)
		{
			if (this.IsUpdatingFromObject) return;
			if (!this.ReadOnly)
			{
				object[] values = this.GetValue().ToArray();
				Vector3 newVal = (Vector3)this.DisplayedValue;
				for (int i = 0; i < values.Length; i++)
				{
					if (values[i] == null)
						values[i] = this.DisplayedValue;
					else
					{
						Vector3 oldVal = (Vector3)values[i];
						values[i] = new Vector3(newVal.X, oldVal.Y, oldVal.Z);
					}
				}
				this.SetValues(values);
			}
			this.PerformGetValue();
		}
Example #38
0
        private void BetterCamera(OpenTK.Vector3 average_point)
        {
            {
                const float yFov = 1.00899694f; // 75
                const float near = 10;
                const float far = 7000;
                float aspect_ratio = GLControl.Width / GLControl.Height;
                OpenTK.Matrix4 projection;
                projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(yFov, aspect_ratio, near, far);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();
                GL.LoadMatrix(ref projection);
            }

            OpenTK.Vector3 eye;

            float radius = Program.camera.GetDistance();
            float theta = Program.camera.GetAngleZ();
            float phi = Program.camera.GetAngleX();

            Program.form.labelAngle.Text = "Angle: " + theta + " " + phi;
            eye.X = radius * (float)Math.Cos((double)theta) * (float)Math.Cos((double)phi);
            eye.Y = radius * (float)Math.Sin((double)theta);
            eye.Z = radius * (float)Math.Cos((double)theta) * (float)Math.Sin((double)phi);

            OpenTK.Vector3 eye_direction = eye;
            eye_direction.Normalize();
            OpenTK.Vector3 zero = new OpenTK.Vector3(0.0f, 0.0f, 0.0f);
            OpenTK.Vector3 up = new OpenTK.Vector3(0.0f, 1.0f, 0.0f);
            OpenTK.Vector3 right = OpenTK.Vector3.Cross(eye_direction, up);
            //up = OpenTK.Vector3.Cross(right, eye_direction);
            OpenTK.Matrix4 lookat;
            lookat = OpenTK.Matrix4.LookAt(eye, zero, up);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.MultMatrix(ref lookat);
            GL.Translate(average_point);
        }
        public static void parsePLYFile(String fileName, CornerTableMesh container)
        {
            int lineNumber = 0;
            StreamReader reader = null;
            string temp = null;

            if (!fileName.EndsWith(".ply"))
            {
                MainMethod.reportError("PolyGonFileParser.parsePLYFile : Filename: \"" + fileName + "\" does not appear to be a polygon file");
            }

            try
            {
                reader = new StreamReader(fileName);
            }
            catch (FileNotFoundException fnfe)
            {
               MainMethod.reportError("PolygonFilePasrer.parsePLYFile : Error could not find file. Exception message:" + fnfe.Message);
               return;
            }

            PLYFileHeader header = new PLYFileHeader();
            lineNumber = parseHeader(reader, header);

            if (lineNumber < 0)
            {
                return;
            }

            List<Colour4f> colourList = new List<Colour4f>();
            OpenTK.Vector3 tempPosition = new OpenTK.Vector3(0.0f, 0.0f, 0.0f);
            OpenTK.Vector3 tempNormal = new OpenTK.Vector3(0.0f, 0.0f, 0.0f);
            Colour4f tempColour = new Colour4f(0.0f, 0.0f, 0.0f, 0.0f);
            int vertexIndex = 0;
            int faceIndex = 0;
            int triangleIndex = 0;

            while (reader.Peek() > -1)
            {
                temp = getNewLine(reader, ref lineNumber);
                //First Parse Vertices
                if (vertexIndex < header.vertexCount)
                {
                    if (String.IsNullOrWhiteSpace(temp))
                    {
                        continue;
                    }

                    vertexIndex++;

                    tempPosition.X = 0.0f;
                    tempPosition.Y = 0.0f;
                    tempPosition.Z = 0.0f;

                    tempColour.red = Config.convertSettingToFloat("colours", "corner_default_red");
                    tempColour.green = Config.convertSettingToFloat("colours", "corner_default_green");
                    tempColour.blue = Config.convertSettingToFloat("colours", "corner_default_blue");
                    tempColour.alpha = Config.convertSettingToFloat("colours", "corner_default_alpha");

                    string[] pieces = temp.Split(' ');

                    if (header.xIndex >= 0)
                    {
                        tempPosition.X = float.Parse(pieces[header.xIndex]);
                    }
                    if (header.yIndex >= 0)
                    {
                        tempPosition.Y = float.Parse(pieces[header.yIndex]);
                    }
                    if (header.zIndex >= 0)
                    {
                        tempPosition.Z = float.Parse(pieces[header.zIndex]);
                    }
                    if(header.normalXIndex >= 0)
                    {
                        tempNormal.X = float.Parse(pieces[header.normalXIndex]);
                    }
                    if(header.normalYIndex >= 0)
                    {
                        tempNormal.Y = float.Parse(pieces[header.normalYIndex]);
                    }
                    if(header.normalZIndex >= 0)
                    {
                        tempNormal.Z = float.Parse(pieces[header.normalZIndex]);
                    }
                    if (header.redIndex >= 0)
                    {
                        tempColour.red = float.Parse(pieces[header.redIndex]);
                    }
                    if (header.greenIndex >= 0)
                    {
                        tempColour.green = float.Parse(pieces[header.greenIndex]);
                    }
                    if (header.blueIndex >= 0)
                    {
                        tempColour.blue = float.Parse(pieces[header.blueIndex]);
                    }
                    if (header.alphaIndex >= 0)
                    {
                        tempColour.alpha = float.Parse(pieces[header.alphaIndex]);
                    }

                    if (header.normalXIndex != -1 && header.normalYIndex != -1 && header.normalZIndex != -1)
                    {
                        container.vertices.Add(new Vertex3f(tempPosition, tempNormal));
                    }
                    else
                    {
                        container.vertices.Add(new Vertex3f(tempPosition));
                    }
                    colourList.Add(new Colour4f(tempColour));

                    if (vertexIndex == header.vertexCount)
                    {
                        header.vertexIndexConversion = weldVertices(ref container.vertices);
                    }
                }
                else if (faceIndex < header.faceCount)
                {
                    if (String.IsNullOrWhiteSpace(temp))
                    {
                        continue;
                    }

                    String[] pieces = temp.Split(' ');

                    if (pieces.Length < 4)
                    {
                        MainMethod.reportError("Not enough information on line: " + lineNumber + " to make a face.");
                        continue;
                    }

                    faceIndex++;

                    if (pieces[0] == "3")
                    {
                        Corner tempCornerOne = new Corner(header.vertexIndexConversion[int.Parse(pieces[1])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[1])]], colourList[int.Parse(pieces[1])], triangleIndex);
                        Corner tempCornerTwo = new Corner(header.vertexIndexConversion[int.Parse(pieces[2])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[2])]], colourList[int.Parse(pieces[2])], triangleIndex);
                        Corner tempCornerThree = new Corner(header.vertexIndexConversion[int.Parse(pieces[3])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[3])]], colourList[int.Parse(pieces[3])], triangleIndex);

                        container.triangles.Add(tempCornerOne);
                        container.triangles.Add(tempCornerTwo);
                        container.triangles.Add(tempCornerThree);
                        triangleIndex++;
                    }
                    else if (pieces[0] == "4")
                    {
                        Corner tempCornerOne = new Corner(header.vertexIndexConversion[int.Parse(pieces[1])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[1])]], colourList[int.Parse(pieces[1])], triangleIndex);
                        Corner tempCornerTwo = new Corner(header.vertexIndexConversion[int.Parse(pieces[2])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[2])]], colourList[int.Parse(pieces[2])], triangleIndex);
                        Corner tempCornerThree = new Corner(header.vertexIndexConversion[int.Parse(pieces[3])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[3])]], colourList[int.Parse(pieces[3])], triangleIndex);
                        triangleIndex++;

                        Corner tempCornerFour = new Corner(header.vertexIndexConversion[int.Parse(pieces[1])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[1])]], colourList[int.Parse(pieces[1])], triangleIndex);
                        Corner tempCornerFive = new Corner(header.vertexIndexConversion[int.Parse(pieces[3])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[3])]], colourList[int.Parse(pieces[3])], triangleIndex);
                        Corner tempCornerSix = new Corner(header.vertexIndexConversion[int.Parse(pieces[4])], container.vertices[header.vertexIndexConversion[int.Parse(pieces[4])]], colourList[int.Parse(pieces[4])], triangleIndex);
                        //Corner tempCornerFour = new Corner(int.Parse(pieces[1]), container.vertices[int.Parse(pieces[1])], colourList[int.Parse(pieces[1])], triangleIndex);
                        //Corner tempCornerFive = new Corner(int.Parse(pieces[3]), container.vertices[int.Parse(pieces[3])], colourList[int.Parse(pieces[3])], triangleIndex);
                        //Corner tempCornerSix = new Corner(int.Parse(pieces[4]), container.vertices[int.Parse(pieces[4])], colourList[int.Parse(pieces[4])], triangleIndex);
                        triangleIndex++;

                        container.triangles.Add(tempCornerOne);
                        container.triangles.Add(tempCornerTwo);
                        container.triangles.Add(tempCornerThree);

                        container.triangles.Add(tempCornerFour);
                        container.triangles.Add(tempCornerFive);
                        container.triangles.Add(tempCornerSix);
                    }
                    else
                    {
                        MainMethod.reportError("Error program does not support meshes that are not quads or triangles");
                    }
                }
                else
                {
                    //We dont' care about lines

                }
            }

            reader.Close();
        }
Example #40
0
		public void SetValue (Vector3 value)
		{
			GL.UseProgram(_parentEffect.CurrentTechnique.Passes[0].shaderProgram);			
			OpenTK.Vector3 vect3 = new OpenTK.Vector3(value.X, value.Y, value.Z);
			_cachedValue = vect3;
			GL.Uniform3(internalIndex,vect3.X, vect3.Y, vect3.Z);
			GL.UseProgram(0);			
		}
Example #41
0
        private void RenderText()
        {
            lock (Prims)
            {
                int primNr = 0;
                foreach (FacetedMesh mesh in Prims.Values)
                {
                    primNr++;
                    Primitive prim = mesh.Prim;
                    if (!string.IsNullOrEmpty(prim.Text))
                    {
                        string text = System.Text.RegularExpressions.Regex.Replace(prim.Text, "(\r?\n)+", "\n");
                        OpenTK.Vector3 screenPos = OpenTK.Vector3.Zero;
                        OpenTK.Vector3 primPos = OpenTK.Vector3.Zero;

                        // Is it child prim
                        FacetedMesh parent = null;
                        if (Prims.TryGetValue(prim.ParentID, out parent))
                        {
                            var newPrimPos = prim.Position * Matrix4.CreateFromQuaternion(parent.Prim.Rotation);
                            primPos = new OpenTK.Vector3(newPrimPos.X, newPrimPos.Y, newPrimPos.Z);
                        }

                        primPos.Z += prim.Scale.Z * 0.8f;
                        if (!Math3D.GluProject(primPos, ModelMatrix, ProjectionMatrix, Viewport, out screenPos)) continue;
                        screenPos.Y = glControl.Height - screenPos.Y;

                        textRendering.Begin();

                        Color color = Color.FromArgb((int)(prim.TextColor.A * 255), (int)(prim.TextColor.R * 255), (int)(prim.TextColor.G * 255), (int)(prim.TextColor.B * 255));
                        TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.Top;

                        using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular))
                        {
                            var size = TextRendering.Measure(text, f, flags);
                            screenPos.X -= size.Width / 2;
                            screenPos.Y -= size.Height;

                            // Shadow
                            if (color != Color.Black)
                            {
                                textRendering.Print(text, f, Color.Black, new Rectangle((int)screenPos.X + 1, (int)screenPos.Y + 1, size.Width, size.Height), flags);
                            }
                            textRendering.Print(text, f, color, new Rectangle((int)screenPos.X, (int)screenPos.Y, size.Width, size.Height), flags);
                        }
                        textRendering.End();
                    }
                }
            }
        }
Example #42
0
 void SetOrientation(Vector3d at, Vector3d up)
 {
     OpenTK.Vector3 iat = new OpenTK.Vector3((float)at.X, (float)at.Y, (float)at.Z), iup = new OpenTK.Vector3((float)up.X, (float)up.Y, (float)up.Z); using (context.Bind()) AL.Listener(ALListenerfv.Orientation, ref iat, ref iup);
 }
Example #43
0
        private void SetupMatrices(int gem_num, float aspect_ratio)
        {
            const float yFov = 0.837758041f;                 // 48 degrees vertical field-of-view
            const float near = 10, far = 3000;         // 50cm to 3m tracking limits (but reduce near to avoid object clipping)

            OpenTK.Matrix4 projection;
            projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(yFov, aspect_ratio, near, far);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(ref projection);

            float cameraPitchAngle = AR_state.gemStates[gem_num].camera_pitch_angle;

            Console.WriteLine("{0}", cameraPitchAngle);

            OpenTK.Matrix4 rotation, scale, lookat;

            rotation = OpenTK.Matrix4.CreateRotationX(cameraPitchAngle);
            scale = OpenTK.Matrix4.Scale(-1.0f, 1.0f, 1.0f);

            lookat = OpenTK.Matrix4.LookAt(0, 0, 0,
                                           0, 0, 1,
                                           0, 1, 0);
            OpenTK.Matrix4 view = lookat * (scale * rotation);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(ref view);
            OpenTK.Matrix4 mv_mat;
            GL.GetFloat(GetPName.ModelviewMatrix, out mv_mat);
            //Console.WriteLine("{0}", mv_mat);
            OpenTK.Vector3 gem_position = new OpenTK.Vector3(AR_state.gemStates[gem_num].pos.x, AR_state.gemStates[gem_num].pos.y, AR_state.gemStates[gem_num].pos.z);
            OpenTK.Quaternion gem_rotation = new OpenTK.Quaternion(AR_state.gemStates[gem_num].quat.x, AR_state.gemStates[gem_num].quat.y, AR_state.gemStates[gem_num].quat.z, AR_state.gemStates[gem_num].quat.w);
            gem_rotation.Normalize();
            OpenTK.Matrix4 gem_rotation_matrix = OpenTK.Matrix4.Rotate(gem_rotation);
            OpenTK.Matrix4 gem_translation_matrix = OpenTK.Matrix4.CreateTranslation(gem_position);
            OpenTK.Matrix4 gem_model_matrix = gem_rotation_matrix;
            gem_model_matrix.M41 = gem_position.X;
            gem_model_matrix.M42 = gem_position.Y;
            gem_model_matrix.M43 = gem_position.Z;
            gem_model_matrix.M44 = 1.0f;
            GL.MultMatrix(ref gem_model_matrix);
        }
Example #44
0
 public VertexPositionColor(OpenTK.Vector3 pos, Color color)
 {
     Position = pos;
     Color = ToRgba(color);
 }
Example #45
0
 public VertexPosition(OpenTK.Vector2 pos)
 {
     // Console.WriteLine(pos);
     Position = new OpenTK.Vector3(pos.X, pos.Y, 0);
 }
        public void Forward(double? distPtr, bool drawLine)
        {
            double distance = distPtr.HasValue ? distPtr.Value : this.Distance;
            if (drawLine)
            {
                float thickness = (float)(this.Thickness / 2);
                float length = (float)distance;

                var currentPosition = OpenTK.Vector3.Transform(zeroVector, stack.Peek().Translation);

                OpenTK.Vector3[] points = new OpenTK.Vector3[numEdges * 2];

                if (this.stack.Peek().fPoints.Count > 0)
                {
                    OpenTK.Vector3 x1 = new OpenTK.Vector3(1, 0, 0);
                    OpenTK.Vector3 vx1 = OpenTK.Vector3.Transform(x1, this.stack.Peek().fMatrix);
                    OpenTK.Vector3 vx2 = OpenTK.Vector3.Transform(x1, this.stack.Peek().Rotation);

                    float angle = OpenTK.Vector3.CalculateAngle(vx1, vx2);
                    OpenTK.Vector3 rotateAxis = OpenTK.Vector3.Cross(vx1, vx2);

                    for (int i = 0; i < numEdges; ++i)
                    {
                        var p = this.stack.Peek().fPoints[numEdges + i] - currentPosition;
                        p.Normalize();

                        if (angle > minAngle)
                        {
                            p = OpenTK.Vector3.Transform(p, OpenTK.Matrix4.CreateFromAxisAngle(rotateAxis, angle));
                        }

                        p = p * thickness;
                        points[i] = currentPosition + p;
                        points[i + numEdges] = currentPosition + p + vx2 * length;
                    }
                }
                else
                {
                    // Create corner points.
                    for (int i = 0; i < numEdges; ++i)
                    {
                        float angle = (float)((i + 0.5f) * (Math.PI * 2) / numEdges);
                        points[i].Y = (float)(thickness * Math.Sin(angle));
                        points[i].Z = (float)(thickness * Math.Cos(angle));
                        points[i].X = 0;

                        points[i] = currentPosition +
                            OpenTK.Vector3.Transform(points[i], stack.Peek().Rotation);

                        points[i + numEdges].Y = (float)(thickness * Math.Sin(angle));
                        points[i + numEdges].Z = (float)(thickness * Math.Cos(angle));
                        points[i + numEdges].X = length;

                        points[i + numEdges] = currentPosition +
                            OpenTK.Vector3.Transform(points[i + numEdges], stack.Peek().Rotation);
                    }
                }

                if (simpleMode)
                {
                    BuildUpperCap(points, stack.Peek().Color);
                    BuildLowerCap(points, stack.Peek().Color);
                }
                else if (this.stack.Peek().fPoints.Count == 0)
                {
                    BuildLowerCap(points, stack.Peek().Color);
                }

                OpenTK.Vector3[] wallPoints = null;

                if (simpleMode)
                {
                    wallPoints = points;
                }
                else
                {
                    var previousPoints = this.stack.Peek().fPoints;
                    if (previousPoints.Count > 0)
                    {
                        // Update end points of previous tube,
                        // and start points of this tube.
                        float angle = AngleBetween(this.stack.Peek().fMatrix, stack.Peek().Rotation);

                        if (angle > minAngle)
                        {
                            float r = angle / (float)(Math.PI / 2);
                            float scale = 1.0f + r * r * r;

                            OpenTK.Vector3 x1 = new OpenTK.Vector3(1, 0, 0);

                            OpenTK.Vector3 v1 = OpenTK.Vector3.Transform(x1, this.stack.Peek().fMatrix);
                            OpenTK.Vector3 v2 = OpenTK.Vector3.Transform(x1, this.stack.Peek().Rotation);
                            OpenTK.Vector3 v3 = (v1 + v2) * 0.5f;
                            v3.Normalize();

                            OpenTK.Vector3 noScaleDirection = OpenTK.Vector3.Cross(v1, v2);
                            OpenTK.Vector3 upDirection = OpenTK.Vector3.Cross(noScaleDirection, v3);

                            for (int i = 0; i < numEdges; ++i)
                            {
                                OpenTK.Vector3 p = (previousPoints[numEdges + i] + points[i]) * 0.5f;
                                OpenTK.Vector3 dir = (p - currentPosition);
                                p = currentPosition +
                                    VectorProjection(noScaleDirection, dir) +
                                    VectorProjection(upDirection, dir) * scale;

                                previousPoints[numEdges + i] = points[i] = p;
                            }
                        }
                        else
                        {
                            for (int i = 0; i < numEdges; ++i)
                            {
                                OpenTK.Vector3 p = (previousPoints[numEdges + i] + points[i]) * 0.5f;
                                previousPoints[numEdges + i] = points[i] = p;
                            }
                        }

                        // Render previous tube.
                        wallPoints = previousPoints.ToArray();
                    }

                    this.stack.Peek().fPoints = points.ToList();
                    this.stack.Peek().fMatrix = stack.Peek().Rotation;
                }

                if (wallPoints != null)
                {
                    BuildWalls(wallPoints, stack.Peek().Color);
                }
            }
            else
            {
                if (this.stack.Peek().fPoints.Count > 0)
                {
                    BuildWalls(
                       stack.Peek().fPoints.ToArray(),
                       stack.Peek().Color);

                    BuildUpperCap(
                        stack.Peek().fPoints.ToArray(),
                        stack.Peek().Color);

                    stack.Peek().fPoints.Clear();
                }
            }

            var offset = OpenTK.Vector3.Transform(
                new OpenTK.Vector3((float)distance, 0, 0),
                stack.Peek().Rotation);

            stack.Peek().Translation = OpenTK.Matrix4.Mult(
                OpenTK.Matrix4.CreateTranslation(offset),
                stack.Peek().Translation);

            var currentPos = OpenTK.Vector3.Transform(zeroVector, stack.Peek().Translation);
            this.minPoint = OpenTK.Vector3.ComponentMin(this.minPoint, currentPos);
            this.maxPoint = OpenTK.Vector3.ComponentMax(this.maxPoint, currentPos);

            if (this.surfacePoints != null)
            {
                this.surfacePoints.Add(currentPos);
                this.surfaceColors.Add(stack.Peek().Color);

                if (this.surfacePoints.Count == 3)
                {
                    // Build new triangle.
                    Add(this.triVertexes, this.surfacePoints[0]);
                    Add(this.triVertexes, this.surfacePoints[1]);
                    Add(this.triVertexes, this.surfacePoints[2]);

                    Add(this.triColors, this.surfaceColors[0]);
                    Add(this.triColors, this.surfaceColors[1]);
                    Add(this.triColors, this.surfaceColors[2]);

                    Add(this.triVertexes, this.surfacePoints[2]);
                    Add(this.triVertexes, this.surfacePoints[1]);
                    Add(this.triVertexes, this.surfacePoints[0]);

                    Add(this.triColors, this.surfaceColors[2]);
                    Add(this.triColors, this.surfaceColors[1]);
                    Add(this.triColors, this.surfaceColors[0]);

                    this.surfacePoints.RemoveAt(1);
                    this.surfaceColors.RemoveAt(1);
                }
            }
        }
Example #47
0
 // TODO: Make asyncable!
 public void SetupVBO()
 {
     List<OpenTK.Vector3> Vertices = new List<OpenTK.Vector3>(XWidth * YWidth * ZWidth);
     List<OpenTK.Vector3> Normals = new List<OpenTK.Vector3>(XWidth * YWidth * ZWidth);
     List<OpenTK.Vector3> TexCoords = new List<OpenTK.Vector3>(XWidth * YWidth * ZWidth);
     List<OpenTK.Vector4> Colrs = new List<OpenTK.Vector4>(XWidth * YWidth * ZWidth);
     List<OpenTK.Vector4> TCOLs = new List<OpenTK.Vector4>(XWidth * YWidth * ZWidth);
     List<OpenTK.Vector3> Tangs = new List<OpenTK.Vector3>(XWidth * YWidth * ZWidth);
     for (int x = 0; x < XWidth; x++)
     {
         for (int y = 0; y < YWidth; y++)
         {
             for (int z = 0; z < ZWidth; z++)
             {
                 BlockInternal c = GetBlockAt(x, y, z);
                 if (((Material)c.BlockMaterial).RendersAtAll())
                 {
                     BlockInternal def = new BlockInternal(0, 0, 0, 0);
                     BlockInternal zp = z + 1 < ZWidth ? GetBlockAt(x, y, z + 1) : def;
                     BlockInternal zm = z > 0 ? GetBlockAt(x, y, z - 1) : def;
                     BlockInternal yp = y + 1 < YWidth ? GetBlockAt(x, y + 1, z) : def;
                     BlockInternal ym = y > 0 ? GetBlockAt(x, y - 1, z) : def;
                     BlockInternal xp = x + 1 < XWidth ? GetBlockAt(x + 1, y, z) : def;
                     BlockInternal xm = x > 0 ? GetBlockAt(x - 1, y, z) : def;
                     bool rAS = !((Material)c.BlockMaterial).GetCanRenderAgainstSelf();
                     bool zps = (zp.IsOpaque() || (rAS && (zp.BlockMaterial == c.BlockMaterial))) && BlockShapeRegistry.BSD[zp.BlockData].OccupiesBOTTOM();
                     bool zms = (zm.IsOpaque() || (rAS && (zm.BlockMaterial == c.BlockMaterial))) && BlockShapeRegistry.BSD[zm.BlockData].OccupiesTOP();
                     bool xps = (xp.IsOpaque() || (rAS && (xp.BlockMaterial == c.BlockMaterial))) && BlockShapeRegistry.BSD[xp.BlockData].OccupiesXM();
                     bool xms = (xm.IsOpaque() || (rAS && (xm.BlockMaterial == c.BlockMaterial))) && BlockShapeRegistry.BSD[xm.BlockData].OccupiesXP();
                     bool yps = (yp.IsOpaque() || (rAS && (yp.BlockMaterial == c.BlockMaterial))) && BlockShapeRegistry.BSD[yp.BlockData].OccupiesYM();
                     bool yms = (ym.IsOpaque() || (rAS && (ym.BlockMaterial == c.BlockMaterial))) && BlockShapeRegistry.BSD[ym.BlockData].OccupiesYP();
                     Vector3 pos = new Vector3(x, y, z);
                     List<BEPUutilities.Vector3> vecsi = BlockShapeRegistry.BSD[c.BlockData].GetVertices(pos, xps, xms, yps, yms, zps, zms);
                     List<BEPUutilities.Vector3> normsi = BlockShapeRegistry.BSD[c.BlockData].GetNormals(pos, xps, xms, yps, yms, zps, zms);
                     List<BEPUutilities.Vector3> tci = BlockShapeRegistry.BSD[c.BlockData].GetTCoords(pos, (Material)c.BlockMaterial, xps, xms, yps, yms, zps, zms);
                     int vertcount = Vertices.Count;
                     for (int i = 0; i < vecsi.Count; i++)
                     {
                         // TODO: is PosMultiplier used correctly here?
                         OpenTK.Vector3 vt = new OpenTK.Vector3((float)vecsi[i].X, (float)vecsi[i].Y, (float)vecsi[i].Z);
                         Vertices.Add(vt);
                         OpenTK.Vector3 nt = new OpenTK.Vector3((float)normsi[i].X, (float)normsi[i].Y, (float)normsi[i].Z);
                         Normals.Add(nt);
                         TexCoords.Add(new OpenTK.Vector3((float)tci[i].X, (float)tci[i].Y, (float)tci[i].Z));
                         Colrs.Add(new OpenTK.Vector4(1, 1, 1, 1));
                         TCOLs.Add(TheClient.Rendering.AdaptColor(vt, Colors.ForByte(c.BlockPaint)));
                     }
                     for (int i = 0; i < vecsi.Count; i += 3)
                     {
                         int basis = vertcount + i;
                         OpenTK.Vector3 v1 = Vertices[basis];
                         OpenTK.Vector3 dv1 = Vertices[basis + 1] - v1;
                         OpenTK.Vector3 dv2 = Vertices[basis + 2] - v1;
                         OpenTK.Vector3 t1 = TexCoords[basis];
                         OpenTK.Vector3 dt1 = TexCoords[basis + 1] - t1;
                         OpenTK.Vector3 dt2 = TexCoords[basis + 2] - t1;
                         OpenTK.Vector3 tangent = (dv1 * dt2.Y - dv2 * dt1.Y) * 1f / (dt1.X * dt2.Y - dt1.Y * dt2.X);
                         OpenTK.Vector3 normal = Normals[basis];
                         tangent = (tangent - normal * OpenTK.Vector3.Dot(normal, tangent)).Normalized();
                         Tangs.Add(tangent);
                         Tangs.Add(tangent);
                         Tangs.Add(tangent);
                     }
                     if (!c.IsOpaque() && BlockShapeRegistry.BSD[c.BlockData].BackTextureAllowed)
                     {
                         int tf = Colrs.Count - vecsi.Count;
                         for (int i = vecsi.Count - 1; i >= 0; i--)
                         {
                             Vertices.Add(new OpenTK.Vector3((float)vecsi[i].X, (float)vecsi[i].Y, (float)vecsi[i].Z));
                             int tx = tf + i;
                             Colrs.Add(Colrs[tx]);
                             TCOLs.Add(TCOLs[tx]);
                             Normals.Add(new OpenTK.Vector3(-(float)normsi[i].X, -(float)normsi[i].Y, -(float)normsi[i].Z));
                             TexCoords.Add(new OpenTK.Vector3((float)tci[i].X, (float)tci[i].Y, (float)tci[i].Z));
                         }
                     }
                 }
             }
         }
     }
     if (vbo != null)
     {
         vbo.Destroy();
         vbo = null;
     }
     if (Vertices.Count == 0)
     {
         return;
     }
     vbo = new VBO();
     vbo.THVs = new List<OpenTK.Vector4>();
     vbo.THWs = new List<OpenTK.Vector4>();
     List<uint> Indices = new List<uint>(Vertices.Count);
     for (uint i = 0; i < Vertices.Count; i++)
     {
         Indices.Add(i);
         vbo.THVs.Add(new OpenTK.Vector4(0, 0, 0, 0));
         vbo.THWs.Add(new OpenTK.Vector4(0, 0, 0, 0));
     }
     vbo.Vertices = Vertices;
     vbo.Normals = Normals;
     vbo.TexCoords = TexCoords;
     vbo.Colors = Colrs;
     vbo.TCOLs = TCOLs;
     vbo.Tangents = Tangs;
     vbo.Indices = Indices;
     vbo.GenerateVBO();
 }
Example #48
0
        private void GLControl_Paint(object sender, PaintEventArgs e)
        {
            if (!glControl_loaded) // Play nice
                return;

            if (Program.client_connected == false || Program.flower.Capturing() == false || Program.camera.SphereVisible())
            {
                GL.ClearColor(Color.Black);
            }
            else
            {
                GL.ClearColor(Color.Red);
            }

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Program.flower.StartRead();

            int current_slot = Program.flower.GetCurrentSlot();
            LinkedList<MoveSample> samples = Program.flower.GetSamples(current_slot);

            // find average point
            OpenTK.Vector3 average_point = new OpenTK.Vector3(0.0f, 0.0f, 0.0f);
            foreach (MoveSample sample in samples) {
                average_point.X += sample.x;
                average_point.Y += sample.y;
                average_point.Z += sample.z;
            }
            average_point /= samples.Count;
            BetterCamera(average_point);
            Program.form.labelCenter.Text = "Position: (" + average_point.X + " , " + average_point.Y + " , " + average_point.Z + ")";
            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            GL.LineWidth(2.0f);

            DrawSphere(20.0f, 8);

            for (int i = 0; i < MoveMeFlowerStateConstants.MAX_FLOWERS; i++)
            {
                LinkedList<MoveSample> slot_samples = Program.flower.GetSamples(i);
                GL.Color3(palette[i].r, palette[i].g, palette[i].b);
                GL.Begin(BeginMode.LineStrip);
                foreach (MoveSample sample in slot_samples)
                {
                    GL.Vertex3(-sample.x, sample.y, -sample.z);
                }
                GL.End();
            }

            /*
            int palette_index = 0;
            GL.Begin(BeginMode.LineStrip);
            foreach (MoveSample sample in samples) {
                GL.Color3(palette[palette_index].r, palette[palette_index].g, palette[palette_index].b);
                GL.Vertex3(-sample.x, sample.y, -sample.z);
                palette_index = (palette_index + 1) % palette.Length;
            }
            GL.End();
             */

            Program.flower.StopRead();
            GLControl.SwapBuffers();
        }
Example #49
0
#pragma warning restore 0612
        private void RenderText()
        {
            lock (Prims)
            {
                int primNr = 0;
                foreach (FacetedMesh mesh in Prims.Values)
                {
                    primNr++;
                    Primitive prim = mesh.Prim;
                    if (!string.IsNullOrEmpty(prim.Text))
                    {
                        string text = System.Text.RegularExpressions.Regex.Replace(prim.Text, "(\r?\n)+", "\n");
                        OpenTK.Vector3 screenPos = OpenTK.Vector3.Zero;
                        OpenTK.Vector3 primPos = OpenTK.Vector3.Zero;

                        // Is it child prim
                        if (prim.ParentID == RootPrimLocalID)
                        {
                            primPos = new OpenTK.Vector3(prim.Position.X, prim.Position.Y, prim.Position.Z);
                        }

                        primPos.Z += prim.Scale.Z * 0.7f;
                        screenPos = WorldToScreen(primPos);
                        Printer.Begin();

                        Color color = Color.FromArgb((int)(prim.TextColor.A * 255), (int)(prim.TextColor.R * 255), (int)(prim.TextColor.G * 255), (int)(prim.TextColor.B * 255));

                        using (Font f = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold))
                        {
                            var size = Printer.Measure(text, f);
                            screenPos.X -= size.BoundingBox.Width / 2;
                            screenPos.Y -= size.BoundingBox.Height;

                            // Shadow
                            if (color != Color.Black)
                            {
                                Printer.Print(text, f, Color.Black, new RectangleF(screenPos.X + 1, screenPos.Y + 1, size.BoundingBox.Width, size.BoundingBox.Height), OpenTK.Graphics.TextPrinterOptions.Default, OpenTK.Graphics.TextAlignment.Center);
                            }
                            Printer.Print(text, f, color, new RectangleF(screenPos.X, screenPos.Y, size.BoundingBox.Width, size.BoundingBox.Height), OpenTK.Graphics.TextPrinterOptions.Default, OpenTK.Graphics.TextAlignment.Center);
                        }
                        Printer.End();
                    }
                }
            }
        }
Example #50
0
 public VertexPosition(float x, float y, float z)
 {
     Position = new OpenTK.Vector3(x, y, z);
 }
Example #51
0
 public VertexPosition(OpenTK.Vector3 pos)
 {
     Position = pos;
 }
 private void ResetState()
 {
     this.stack.Clear();
     this.minPoint = zeroVector;
     this.maxPoint = zeroVector;
 }
Example #53
0
 public VertexPositionColor(float x, float y, float z, Color color)
 {
     Position = new OpenTK.Vector3(x, y, z);
     Color = ToRgba(color);
 }
        private void toolStripButtonUndoCamera_Click(object sender, EventArgs e)
        {
            this.cameraAngle = new OpenTK.Vector3(0, 0, 0);
            this.cameraScale = 1.0f;

            this.glControl1.Invalidate();
        }
Example #55
0
 public VertexPositionColor(OpenTK.Vector2 pos, System.Drawing.Color color)
 {
     Position = new OpenTK.Vector3(pos.X, pos.Y, 0);
     Color = ToRgba(color);
 }
Example #56
0
 public Vertex3f(float x, float y, float z, float normalX, float normalY, float normalZ)
     : this(x, y, z)
 {
     this.normal = new OpenTK.Vector3(normalX, normalY, normalZ);
 }
        private static List<OpenTK.Vector3> GetQuarter(
            float a, float b, OpenTK.Vector3 top, 
            OpenTK.Vector3 L1,       OpenTK.Quaternion rot, 
            int resolution,         int p, float scale)
        {
            OpenTK.Quaternion extraRot = OpenTK.Quaternion.Identity;
            OpenTK.Vector3 L2 = L1;
            if (a > 90 && b > 90)
            {
                L2 = -L1;
                a = 180 - a;
                b = 180 - b;
            }
            else if ((a > 90) ^ (b > 90))
            {
            #region Crazy cone
                OpenTK.Vector3 right = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitX, rot);
                OpenTK.Vector3 forward = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitZ, rot);
                L2 = right;
                switch (p)
                {
                case 1:
                    if (a > 90) L2 = right;
                    else L2 = forward;
                    break;
                case 2:
                    if (a > 90) L2 = -right;
                    else L2 = forward;
                    break;
                case 3:
                    if (a > 90) L2 = -right;
                    else L2 = -forward;
                    break;
                case 4:
                    if (a > 90) L2 = right;
                    else L2 = -forward;
                    break;
                default:
                    break;
                }
                if (a > 90)
                    a = a - 90;
                else
                    b = b - 90;
                float angle = OpenTK.Vector3.CalculateAngle(L2, L1);
                OpenTK.Vector3 axis = OpenTK.Vector3.Cross(L2, L1);
                extraRot = OpenTK.Quaternion.FromAxisAngle(axis, angle);
                extraRot = OpenTK.Quaternion.Invert(extraRot);
            #endregion
            }

            float A = Mathf.Tan(OpenTK.MathHelper.DegreesToRadians(Math.Min(89.99f, a)));
            float B = Mathf.Tan(OpenTK.MathHelper.DegreesToRadians(Math.Min(89.99f, b)));
            List<OpenTK.Vector3> te = new List<OpenTK.Vector3>();
            float part = resolution * (p / 4f);
            float start = resolution * ((p - 1f) / 4f);
            for (float i = start; i < part; i++)
            {
                float angle = i / resolution * 2.0f * Mathf.PI;
                float x = A * Mathf.Cos(angle);
                float z = B * Mathf.Sin(angle);
                OpenTK.Vector3 t = new OpenTK.Vector3(x, 0.0f, z );
                t = OpenTK.Vector3.Transform(t, extraRot * rot );
                t += L2;
                t.Normalize();
                t *= scale;
                t += top;
                te.Add(t);
            }
            return te;
        }
Example #58
0
        ObjModel CreateSphere(double R, double H, double K, double Z)
        {
            List<OpenTK.Vector3> Vertecies = new List<OpenTK.Vector3>();
            List<OpenTK.Vector2> TextCoords = new List<OpenTK.Vector2>();
            int n;
            double a;
            double b;
            n = 0;
            for (b = 0; b <= 90 - space; b += space) {
                for (a = 0; a <= 360 - space; a += space) {
                    var v1 = new OpenTK.Vector3((float)(R * Math.Sin ((a) / 180 * Math.PI ) * Math.Sin ((b) / 180 * Math.PI) - H),
                                         (float)(R * Math.Cos ((a) / 180 * Math.PI ) * Math.Sin ((b) / 180 * Math.PI ) + K),
                                         (float)(R * Math.Cos ((b) / 180 * Math.PI ) - Z));
                    var t1 = new OpenTK.Vector2((float)((2 * b) / 360),(float)((a) / 360));
                    n++;

                    var v2 = new OpenTK.Vector3((float)(R * Math.Sin ((a) / 180 * Math.PI ) * Math.Sin ((b + space) / 180 * Math.PI ) - H),
                                         (float)(R * Math.Cos ((a) / 180 * Math.PI ) * Math.Sin ((b + space) / 180 * Math.PI ) + K),
                                         (float)(R * Math.Cos ((b + space) / 180 * Math.PI ) - Z));
                    var t2 = new OpenTK.Vector2((float)((2 * (b + space)) / 360),
                                         (float)((a) / 360));
                    n++;

                    var v3 = new OpenTK.Vector3((float)(R * Math.Sin ((a + space) / 180 * Math.PI ) * Math.Sin ((b) / 180 * Math.PI ) - H),
                                         (float)(R * Math.Cos ((a + space) / 180 * Math.PI ) * Math.Sin ((b) / 180 * Math.PI ) + K),
                                         (float)(R * Math.Cos ((b) / 180 * Math.PI ) - Z));
                    var t3 = new OpenTK.Vector2((float)((2 * b) / 360),
                                         (float)((a + space) / 360));
                    n++;

                    var v4 = new OpenTK.Vector3((float)( R * Math.Sin ((a + space) / 180 * Math.PI ) * Math.Sin ((b + space) / 180 * Math.PI ) - H),
                                         (float)(R * Math.Cos ((a + space) / 180 * Math.PI ) * Math.Sin ((b + space) / 180 * Math.PI ) + K),
                                         (float)(R * Math.Cos ((b + space) / 180 * Math.PI ) - Z));
                    var t4 = new OpenTK.Vector2((float)((2 * (b + space)) / 360),
                                         (float)((a + space) / 360));
                    n++;

                    Vertecies.Add(v1);
                    Vertecies.Add(v2);
                    Vertecies.Add(v3);
                    Vertecies.Add(v4);

                    TextCoords.Add(t1);
                    TextCoords.Add(t2);
                    TextCoords.Add(t3);
                    TextCoords.Add(t4);

                }
            }
            return new ObjModel(){Verticies = Vertecies.ToArray(),
                                TextureCoords = TextCoords.ToArray()};
        }