public static void AssertEquals(TK.Vector4 v1, TK.Vector4 v2, String msg) { AssertEquals(v1.X, v2.X, msg + String.Format(" => checking X component ({0} == {1}", v1.X, v2.X)); AssertEquals(v1.Y, v2.Y, msg + String.Format(" => checking Y component ({0} == {1}", v1.Y, v2.Y)); AssertEquals(v1.Z, v2.Z, msg + String.Format(" => checking Z component ({0} == {1}", v1.Z, v2.Z)); AssertEquals(v1.W, v2.W, msg + String.Format(" => checking W component ({0} == {1}", v1.W, v2.W)); }
public override void Render() { if (!Visible || model.Meshes.Count == 0) { return; } TheClient.SetEnts(); RigidTransform rt = new RigidTransform(Body.Position, Body.Orientation); BEPUutilities.Vector3 bmin; BEPUutilities.Vector3 bmax; RigidTransform.Transform(ref ModelMin, ref rt, out bmin); RigidTransform.Transform(ref ModelMax, ref rt, out bmax); if (TheClient.MainWorldView.CFrust != null && !TheClient.MainWorldView.CFrust.ContainsBox(bmin, bmax)) { return; } Matrix4d orient = GetOrientationMatrix(); Matrix4d mat = transform * (Matrix4d.Scale(ClientUtilities.ConvertD(scale)) * orient * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(GetPosition()))); TheClient.MainWorldView.SetMatrix(2, mat); TheClient.Rendering.SetMinimumLight(0.0f); if (model.Meshes[0].vbo.Tex == null) { TheClient.Textures.White.Bind(); } if (TheClient.CVars.r_fast.ValueB || !TheClient.CVars.r_lighting.ValueB) { OpenTK.Vector4 sadj = TheRegion.GetSunAdjust(); float skyl = TheRegion.GetSkyLightBase(GetPosition() + new Location(0, 0, ModelMax.Z)); TheClient.Rendering.SetColor(new OpenTK.Vector4(sadj.X * skyl, sadj.Y * skyl, sadj.Z * skyl, 1.0f)); } model.Draw(); // TODO: Animation(s)? }
public static Vector3 QuaternionToEuler(OpenTK.Vector4 q) { Vector3 v = Vector3.Zero; v.X = (float)Math.Atan2(2 * q.Y * q.W - 2 * q.X * q.Z, 1 - 2 * Math.Pow(q.Y, 2) - 2 * Math.Pow(q.Z, 2)); v.Z = (float)Math.Asin(2 * q.X * q.Y + 2 * q.Z * q.W); v.Y = (float)Math.Atan2(2 * q.X * q.W - 2 * q.Y * q.Z, 1 - 2 * Math.Pow(q.X, 2) - 2 * Math.Pow(q.Z, 2)); if (q.X * q.Y + q.Z * q.W == 0.5) { v.X = (float)(2 * Math.Atan2(q.X, q.W)); v.Y = 0; } else if (q.X * q.Y + q.Z * q.W == -0.5) { v.X = (float)(-2 * Math.Atan2(q.X, q.W)); v.Y = 0; } v.X = RadianToDegree(v.X); v.Y = RadianToDegree(v.Y); v.Z = RadianToDegree(v.Z); return(v); }
public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null) { var data = (NTRO)Resource.Blocks[BlockType.DATA]; var refMeshes = (NTROArray)data.Output["m_refMeshes"]; var materialGroups = (NTROArray)data.Output["m_materialGroups"]; for (var i = 0; i < refMeshes.Count; i++) { var refMesh = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)refMeshes[i]).Value; var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh.Name + "_c", path, currentPackage); if (newResource == null) { Console.WriteLine("unable to load mesh " + refMesh.Name); continue; } if (!newResource.Blocks.ContainsKey(BlockType.VBIB)) { Console.WriteLine("Old style model, no VBIB!"); continue; } var skinMaterials = new List<string>(); if (!string.IsNullOrEmpty(skin)) { foreach (var materialGroup2 in materialGroups) { var materialGroup = ((NTROValue<NTROStruct>)materialGroup2).Value; if (((NTROValue<string>)materialGroup["m_name"]).Value == skin) { var materials = (NTROArray)materialGroup["m_materials"]; foreach (var material in materials) { skinMaterials.Add(((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)material).Value.Name); } break; } } } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = transform, TintColor = tintColor, SkinMaterials = skinMaterials }); // TODO: Only first, again. break; } }
internal ErrorReportVerticesBlockBase(BinaryReader binaryReader) { this.position = binaryReader.ReadVector3(); this.nodeIndices = new [] { new NodeIndices(binaryReader), new NodeIndices(binaryReader), new NodeIndices(binaryReader), new NodeIndices(binaryReader), }; this.nodeWeights = new [] { new NodeWeights(binaryReader), new NodeWeights(binaryReader), new NodeWeights(binaryReader), new NodeWeights(binaryReader), }; this.color = binaryReader.ReadVector4(); this.screenSize = binaryReader.ReadSingle(); }
internal StructureBspFogPlaneBlockBase(BinaryReader binaryReader) { this.scenarioPlanarFogIndex = binaryReader.ReadInt16(); this.invalidName_ = binaryReader.ReadBytes(2); this.plane = binaryReader.ReadVector4(); this.flags = (Flags)binaryReader.ReadInt16(); this.priority = binaryReader.ReadInt16(); }
public OpenTK.Vector4 Regularize(OpenTK.Vector4 col) { if (col.X < 1.0 && col.Y < 1.0 && col.Z < 1.0) { return(col); } return(new OpenTK.Vector4(col.Xyz / Math.Max(col.X, Math.Max(col.Y, col.Z)), col.W)); }
public Material(OpenTK.Vector3 col, OpenTK.Vector4 Light, float reflection, float refraction, int type) { Color = col; LightCoeffs = Light; ReflectionCoef = reflection; RefractionCoef = refraction; MaterilaType = type; }
public OpenTK.Vector4 RegularizeBig(OpenTK.Vector4 col, float cap) { if (col.X < cap && col.Y < cap && col.Z < cap) { return(col); } return(new OpenTK.Vector4((col.Xyz / Math.Max(col.X, Math.Max(col.Y, col.Z))) * cap, col.W)); }
internal ErrorReportCommentsBlockBase(BinaryReader binaryReader) { this.text = ReadData(binaryReader); this.position = binaryReader.ReadVector3(); this.nodeIndices = new [] { new NodeIndices(binaryReader), new NodeIndices(binaryReader), new NodeIndices(binaryReader), new NodeIndices(binaryReader), }; this.nodeWeights = new [] { new NodeWeights(binaryReader), new NodeWeights(binaryReader), new NodeWeights(binaryReader), new NodeWeights(binaryReader), }; this.color = binaryReader.ReadVector4(); }
public OpenTK.Vector4 GetLightAmountAdjusted(Location pos, Location norm) { OpenTK.Vector4 vec = new OpenTK.Vector4(ClientUtilities.Convert(GetLightAmount(pos, norm, null)), 1.0f) * GetSunAdjust(); if (TheClient.CVars.r_fast.ValueB) { return(Regularize(vec)); } return(RegularizeBig(vec, 5f)); }
public GLVertex(OpenTK.Vector4 a_v4Position, Color4 a_oColor, OpenTK.Vector2 a_v2UV) { m_v4Position = a_v4Position; // We order the color RGBA because this is the order expected by OpenGL/Graphics card. m_v4Color.X = a_oColor.R / 255.0f; m_v4Color.Y = a_oColor.G / 255.0f; m_v4Color.Z = a_oColor.B / 255.0f; m_v4Color.W = a_oColor.A / 255.0f; m_v2UV = a_v2UV; }
public GLVertex(OpenTK.Vector4 a_v4Position, System.Drawing.Color a_oColor, OpenTK.Vector2 a_v2UV) { m_v4Position = a_v4Position; // We order the color RGBA because this is the order expected by OpenGL/Graphics card. m_v4Color.X = a_oColor.R / 255.0f; m_v4Color.Y = a_oColor.G / 255.0f; m_v4Color.Z = a_oColor.B / 255.0f; m_v4Color.W = a_oColor.A / 255.0f; m_v2UV = a_v2UV; }
public static void AssertEquals(TK.Matrix4 tkM, Matrix3x3 mat, String msg) { //Note: OpenTK 4x4 matrix is a row-vector matrix, so compare rows to AssimpNet Matrix3x3 columns TK.Vector4 row0 = tkM.Row0; TK.Vector4 row1 = tkM.Row1; TK.Vector4 row2 = tkM.Row2; AssertEquals(row0.X, row0.Y, row0.Z, new Vector3D(mat.A1, mat.B1, mat.C1), msg + " => checking first column vector"); AssertEquals(row1.X, row1.Y, row1.Z, new Vector3D(mat.A2, mat.B2, mat.C2), msg + " => checking second column vector"); AssertEquals(row2.X, row2.Y, row2.Z, new Vector3D(mat.A3, mat.B3, mat.C3), msg + " => checking third column vector"); }
public static Vector4 Project(OpenTK.Vector4 objPos, ref Matrix4 projection, Matrix4 view, Size viewport) { Vector4 vec = objPos; vec = Vector4.Transform(vec, Matrix4.Mult(projection, view)); vec.X = (vec.X + 1) * (viewport.Width / 2); vec.Y = (vec.Y + 1) * (viewport.Height / 2); return(vec); }
public static float[] quat2Deg(OpenTK.Vector4 vec) { float[] value = new float[3]; value[0] = (float)Math.Atan2(2 * (vec.W * vec.X + vec.Y * vec.Z), 1 - 2 * (Math.Pow(vec.X, 2) + Math.Pow(vec.Y, 2))); value[1] = (float)Math.Asin(2 * (vec.W * vec.Y - vec.Z * vec.X)); value[2] = (float)Math.Atan2(2 * (vec.W * vec.Z + vec.X * vec.Y), 1 - 2 * (Math.Pow(vec.Y, 2) + Math.Pow(vec.Z, 2))); value[0] = value[0] * (180 / (float)Math.PI); value[1] = value[1] * (180 / (float)Math.PI); value[2] = value[2] * (180 / (float)Math.PI); return(value); }
public void SetShaderProgram(ShaderProgram program) { if (program != null) { program.__linkProgram(); __curProgramObject = program.__programObject; __curProgram = program; if (program.__programObject != 0) { __isUsedProgram[program.__programObject] = true; __programDic[program.__programObject] = program; __vertexBuffer.Clear(); //FIXME:?????? clear, because __programObject in UseProgram(program.__programObject) is changed //__textureDic.Clear(); //FIXME:?????? clear, because __programObject in UseProgram(program.__programObject) is changed //GL.Clear(ClearBufferMask.DepthBufferBit); //FIXME:??? GL.UseProgram(program.__programObject); foreach (int location in program.__uniformMatrix4.Keys) { OpenTK.Matrix4 v = program.__uniformMatrix4[location]; GL.UniformMatrix4(location, false, ref v); // if (program.__filename.Equals("/Application/Sample/Graphics/ShaderCatalogSample/shaders/Simple.cgx")) // { // Debug.WriteLine("======================location2:" + location + " : " + v.ToString()); // } } foreach (int location in program.__uniform4.Keys) { OpenTK.Vector4 v = program.__uniform4[location]; GL.Uniform4(location, v.X, v.Y, v.Z, v.W); } foreach (int location in program.__uniform3.Keys) { OpenTK.Vector3 v = program.__uniform3[location]; GL.Uniform3(location, v.X, v.Y, v.Z); } foreach (int location in program.__uniform1.Keys) { float v = program.__uniform1[location]; GL.Uniform1(location, v); } program.__afterUseProgram(); } else { //FIXME: } } else { __curProgramObject = 0; //FIXME: __curProgram = null; } }
private void fillMaterials() { OpenTK.Vector4 lightCoeffs = new OpenTK.Vector4(0.4f, 0.9f, 0.2f, 2.0f); materials[0] = new Material(new OpenTK.Vector3(0, 1, 0), lightCoeffs, 0.5f, 1, DIFFUSE_REFLECTION); materials[1] = new Material(new OpenTK.Vector3(1, 0, 0), lightCoeffs, 0.5f, 1, DIFFUSE_REFLECTION); materials[2] = new Material(new OpenTK.Vector3(0, 0, 1), lightCoeffs, 0.5f, 1, DIFFUSE_REFLECTION); materials[3] = new Material(new OpenTK.Vector3(1, 1, 0), lightCoeffs, 0.5f, 1, MIRROR_REFLECTION); materials[4] = new Material(new OpenTK.Vector3(0, 1, 1), lightCoeffs, 0.5f, 1, DIFFUSE_REFLECTION); materials[5] = new Material(new OpenTK.Vector3(1, 0, 1), lightCoeffs, 1, 1, MIRROR_REFLECTION); materials[6] = new Material(new OpenTK.Vector3(0.5f, 0.5f, 1), lightCoeffs, 1, 1.5f, REFRACTION); materials[7] = new Material(new OpenTK.Vector3(0.5f, 0.5f, 0.5f), lightCoeffs, 1, 1.5f, DIFFUSE_REFLECTION); materials[8] = new Material(new OpenTK.Vector3(0.5f, 0.5f, 1), lightCoeffs, 1, 1.5f, DIFFUSE_REFLECTION); }
public static OpenTK.Vector4 LeftMultiply(OpenTK.Vector3 tmp, OpenTK.Matrix4 mat) { OpenTK.Vector4 vec = new OpenTK.Vector4(tmp); vec.W = 1; OpenTK.Vector4 ret = new OpenTK.Vector4(); ret.X = vec.X * mat.M11 + vec.Y * mat.M21 + vec.Z * mat.M31 + vec.W * mat.M41; ret.Y = vec.X * mat.M12 + vec.Y * mat.M22 + vec.Z * mat.M32 + vec.W * mat.M42; ret.Z = vec.X * mat.M13 + vec.Y * mat.M23 + vec.Z * mat.M33 + vec.W * mat.M43; ret.W = vec.X * mat.M14 + vec.Y * mat.M24 + vec.Z * mat.M34 + vec.W * mat.M44; return(ret); }
public static OpenTK.Vector4 RightMultiply(OpenTK.Matrix4 mat, OpenTK.Vector3 tmp) { OpenTK.Vector4 vec = new OpenTK.Vector4(tmp); vec.W = 1; OpenTK.Vector4 ret = new OpenTK.Vector4(); ret.X = mat.M11 * vec.X + mat.M12 * vec.Y + mat.M13 * vec.Z + mat.M14 * vec.W; ret.Y = mat.M21 * vec.X + mat.M22 * vec.Y + mat.M23 * vec.Z + mat.M24 * vec.W; ret.Z = mat.M31 * vec.X + mat.M32 * vec.Y + mat.M33 * vec.Z + mat.M34 * vec.W; ret.W = mat.M41 * vec.X + mat.M42 * vec.Y + mat.M43 * vec.Z + mat.M44 * vec.W; return(ret); }
protected override void OnLoad(EventArgs e) { var black = new OpenTK.Vector4(0.0f, 0.0f, 0.0f, 1.0f); var yellow = new OpenTK.Vector4(1.0f, 1.0f, 0.0f, 1.0f); var cyan = new OpenTK.Vector4(0.0f, 1.0f, 1.0f, 1.0f); var white = new OpenTK.Vector4(1.0f, 1.0f, 1.0f, 1.0f); var direction = new OpenTK.Vector4(1.0f, 1.0f, 1.0f, 0.0f); GL.Material(MaterialFace.Front, MaterialParameter.AmbientAndDiffuse, cyan); GL.Material(MaterialFace.Front, MaterialParameter.Specular, white); GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 30f); GL.Light(LightName.Light0, LightParameter.Ambient, black); GL.Light(LightName.Light0, LightParameter.Diffuse, yellow); GL.Light(LightName.Light0, LightParameter.Specular, white); GL.Light(LightName.Light0, LightParameter.Position, direction); //GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 0.2f, 0.2f, 0.2f, 1.0f }); //GL.LightModel(LightModelParameter.LightModelTwoSide, 1); //GL.LightModel(LightModelParameter.LightModelLocalViewer, 1); GL.Enable(EnableCap.Lighting); // so the renderer considers light GL.Enable(EnableCap.Light0); // turn LIGHT0 on GL.Enable(EnableCap.DepthTest); // so the renderer considers depth // Set the current clear color to sky blue and the current drawing color to white. GL.ClearColor(0.1f, 0.39f, 0.88f, 1.0f); GL.Color3(1.0, 1.0, 1.0); float aspect_ratio = Width / (float)Height; // Aspect ratio of the screen float fov = MathHelper.PiOver2; // camera field of view float near_distance = 0.1f; // The nearest the camera can see. >= 0.1f else clips float far_distance = 100.0f; // Fartherest the camera can see OpenTK.Matrix4 perspective_matrix = OpenTK.Matrix4.CreatePerspectiveFieldOfView(fov, aspect_ratio, near_distance, far_distance); ////Then we tell GL to use are matrix as the new Projection matrix. GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref perspective_matrix); GL.Enable(EnableCap.DepthTest); // 'Enable correct Z Drawings GL.DepthFunc(DepthFunction.Less); // 'Enable correct Z Drawings //GL.Viewport(0, 0, Width, Height); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); //GL.ShadeModel(ShadingModel.Smooth); // TODO - requires vertex normals to be calulated across polys }
public Triangle(Vector4 point0, Vector4 point1, Vector4 point2, Color4 color0, Color4 color1, Color4 color2, float4 norm0, float4 norm1, float4 norm2) { p0 = point0; p1 = point1; p2 = point2; c0 = color0; c1 = color1; c2 = color2; n0 = norm0; n1 = norm1; n2 = norm2; }
public bool UpdateUniform(String name, OpenTK.Vector4 vec) { bool result = true; GL.Uniform4(uniforms[name], ref vec); ErrorCode error = GL.GetError(); if (error != ErrorCode.NoError) { result = false; } return(result); }
public static Vector3 QuaternionToYawPitchRoll(this OpenTK.Vector4 q) { const float Epsilon = 0.0009765625f; const float Threshold = 0.5f - Epsilon; float yaw; float pitch; float roll; float XY = q.X * q.Y; float ZW = q.Z * q.W; float TEST = XY + ZW; if (TEST < -Threshold || TEST > Threshold) { int sign = Math.Sign(TEST); yaw = sign * 2 * (float)Math.Atan2(q.X, q.W); pitch = sign * (float)(Math.PI / 2.0f); roll = 0; } else { float XX = q.X * q.X; float XZ = q.X * q.Z; float XW = q.X * q.W; float YY = q.Y * q.Y; float YW = q.Y * q.W; float YZ = q.Y * q.Z; float ZZ = q.Z * q.Z; yaw = (float)Math.Atan2(2 * YW - 2 * XZ, 1 - 2 * YY - 2 * ZZ); pitch = (float)Math.Atan2(2 * XW - 2 * YZ, 1 - 2 * XX - 2 * ZZ); roll = (float)Math.Asin(2 * TEST); }//if return(new Vector3() { X = yaw, Y = pitch, Z = roll }); }//method
public Triangle(Vector4 point0, Vector4 point1, Vector4 point2) { p0 = point0; p1 = point1; p2 = point2; // Use default vertex color c0 = c1 = c2 = Color4.HotPink; // Use cross probuct to compute default normals Vector3 edge1 = new Vector3(point1 - point0); Vector3 edge2 = new Vector3(point2 - point0); Vector3 norm = Vector3.Cross(edge1, edge2); norm.Normalize(); n0 = n1 = n2 = new float4(norm); }
/// <summary> /// General entity render. /// </summary> public override void Render() { if (!Visible || model.Meshes.Count == 0) { return; } TheClient.SetEnts(); RigidTransform rt = new RigidTransform(Body.Position, Body.Orientation); RigidTransform.Transform(ref ModelMin, ref rt, out BEPUutilities.Vector3 bmin); RigidTransform.Transform(ref ModelMax, ref rt, out BEPUutilities.Vector3 bmax); if (TheClient.MainWorldView.CFrust != null && !TheClient.MainWorldView.CFrust.ContainsBox(new Location(bmin), new Location(bmax))) { return; } double maxr = TheClient.CVars.r_modeldistance.ValueF; double distsq = GetPosition().DistanceSquared(TheClient.MainWorldView.RenderRelative); if (GenBlockShadows && distsq > maxr * maxr) // TODO: LOD-able option? { // TODO: Rotation? model.DrawLOD(GetPosition() + ClientUtilities.ConvertD(transform.ExtractTranslation()), TheClient.MainWorldView); return; } Matrix4d orient = GetOrientationMatrix(); Matrix4d mat = (Matrix4d.Scale(ClientUtilities.ConvertD(scale)) * transform * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(new Location(Body.CollisionInformation.LocalPosition))) * orient * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(GetPosition()))); TheClient.MainWorldView.SetMatrix(2, mat); if (!TheClient.MainWorldView.RenderingShadows) { TheClient.Rendering.SetMinimumLight(0.0f, TheClient.MainWorldView); } if (model.Meshes[0].vbo.Tex == null) { TheClient.Textures.White.Bind(); } if (!TheClient.MainWorldView.RenderingShadows && ((TheClient.CVars.r_fast.ValueB && !TheClient.CVars.r_forward_lights.ValueB) || !TheClient.CVars.r_lighting.ValueB)) { OpenTK.Vector4 sadj = TheRegion.GetSunAdjust(); float skyl = TheRegion.GetSkyLightBase(GetPosition() + new Location(0, 0, ModelMax.Z)); TheClient.Rendering.SetColor(new OpenTK.Vector4(sadj.X * skyl, sadj.Y * skyl, sadj.Z * skyl, 1.0f), TheClient.MainWorldView); } model.Draw(); // TODO: Animation(s)? }
public Triangle(Vector3 point0, Vector3 point1, Vector3 point2, Color4 color0, Color4 color1, Color4 color2) { p0 = new Vector4(point0, 1.0f); p1 = new Vector4(point1, 1.0f); p2 = new Vector4(point2, 1.0f); c0 = color0; c1 = color1; c2 = color2; // Use cross probuct to compute default normals Vector3 edge1 = new Vector3(point1 - point0); Vector3 edge2 = new Vector3(point2 - point0); Vector3 norm = Vector3.Cross(edge1, edge2); norm.Normalize(); n0 = n1 = n2 = new float4(norm); }
public void SetUniformValue(int index, ref Vector4 value) { this.__linkProgram(); //TODO: //Debug.Assert(false); OpenTK.Vector4 v = new OpenTK.Vector4(value.X, value.Y, value.Z, value.W); int location = __uniformDic[index].location; __uniform4[location] = v; if (__programObject != 0) { if (GraphicsContext.__isUsedProgram.ContainsKey(__programObject) && GraphicsContext.__isUsedProgram[__programObject]) { GL.Uniform4(location, v.X, v.Y, v.Z, v.W); } } }
internal ErrorReportsBlockBase(BinaryReader binaryReader) { this.type = (Type)binaryReader.ReadInt16(); this.flags = (Flags)binaryReader.ReadInt16(); this.text = ReadData(binaryReader); this.sourceFilename = binaryReader.ReadString32(); this.sourceLineNumber = binaryReader.ReadInt32(); this.vertices = ReadErrorReportVerticesBlockArray(binaryReader); this.vectors = ReadErrorReportVectorsBlockArray(binaryReader); this.lines = ReadErrorReportLinesBlockArray(binaryReader); this.triangles = ReadErrorReportTrianglesBlockArray(binaryReader); this.quads = ReadErrorReportQuadsBlockArray(binaryReader); this.comments = ReadErrorReportCommentsBlockArray(binaryReader); this.invalidName_ = binaryReader.ReadBytes(380); this.reportKey = binaryReader.ReadInt32(); this.nodeIndex = binaryReader.ReadInt32(); this.boundsX = binaryReader.ReadRange(); this.boundsY = binaryReader.ReadRange(); this.boundsZ = binaryReader.ReadRange(); this.color = binaryReader.ReadVector4(); this.invalidName_0 = binaryReader.ReadBytes(84); }
protected override void onClickOculusGrip(ref VREvent_t vrEvent) { if (targetPRhObjID == Guid.Empty || currentState != State.READY) { return; } currentState = State.MOVEPLANE; movePlaneRef = new ObjRef(targetPRhObjID); lastTranslate = 0.0f; //get the plane info RhinoObject movePlaneObj = movePlaneRef.Object(); planeNormal = new Rhino.Geometry.Vector3d(); //PointOnObject still null at this point if (movePlaneObj.Attributes.Name.Contains("planeXY")) { planeNormal = new Rhino.Geometry.Vector3d(0, 0, 1); } else if (movePlaneObj.Attributes.Name.Contains("planeYZ")) { planeNormal = new Rhino.Geometry.Vector3d(1, 0, 0); } else if (movePlaneObj.Attributes.Name.Contains("planeXZ")) { planeNormal = new Rhino.Geometry.Vector3d(0, 1, 0); } OpenTK.Vector4 controller_p = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1); OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)); float translate = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length; //move from the porjection point not origin moveControlerOrigin = new Point3d(0 + translate * planeNormal.X, 0 + translate * planeNormal.Y, 0 + translate * planeNormal.Z); }
public void DrawLine(int x, int y, int x2, int y2, OpenTK.Vector4 col) { // Pen2D.BlendMod = PenBlend.Solid; // Pen2D.Line(GX + x, GY + y, GX + x2, GY + y2); }
protected void SavePBOhdr(string fileName) { OGLBuffer buffer = OutputBuffer as OGLBuffer; if (buffer == null) return; Vector4[] data = new Vector4[buffer.Width * buffer.Height]; buffer.GetDataNoAlloc<Vector4>(data); using (var bmp = new FreeImageBitmap(this.Width, this.Height, FREE_IMAGE_TYPE.FIT_RGBF)) { for (var j = 0ul; j < buffer.Height; j++) { var scanLine = bmp.GetScanline<FIRGBF>((int)buffer.Height - (int)j - 1); for (var i = 0ul; i < buffer.Width; i++) { var px = data[(int)i + (int)(buffer.Height - j - 1) * bmp.Width]; scanLine[(int)i] = new FIRGBF() { red = px.X, green = px.Y, blue = px.Z}; } } bmp.Save(fileName, FREE_IMAGE_FORMAT.FIF_EXR); } }
public ShaderDefinition.vec4 Convert(Vector4 v) { var v4 = new OpenTK.Vector4(v.X, v.Y, v.Z, v.W); return v4.ToVector4F(); }
protected void SetUpLighting() { GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); //m_GL.Enable(OpenGL.GL_LIGHT1); GL.LightModel(LightModelParameter.LightModelTwoSide, 1); OpenTK.Vector4 ambient = new OpenTK.Vector4(0.0f, 0.0f, 0.0f, 1.0f); OpenTK.Vector4 diffuse = new OpenTK.Vector4(1.0f, 1.0f, 1.0f, 1.0f); OpenTK.Vector4 specular = new OpenTK.Vector4(0.3f, 0.3f, 0.3f, 1.0f); OpenTK.Vector4 position0 = new OpenTK.Vector4(0.0f, 0.0f, 1.0f, 0.0f); GL.Light(LightName.Light0, LightParameter.Ambient, ambient); GL.Light(LightName.Light0, LightParameter.Diffuse, diffuse); GL.Light(LightName.Light0, LightParameter.Specular, specular); GL.Light(LightName.Light0, LightParameter.Position, position0); //m_GL.Light(OpenGL.GL_LIGHT1, OpenGL.GL_AMBIENT, ambient); //m_GL.Light(OpenGL.GL_LIGHT1, OpenGL.GL_DIFFUSE, diffuse); //m_GL.Light(OpenGL.GL_LIGHT1, OpenGL.GL_SPECULAR, specular); //m_GL.Light(OpenGL.GL_LIGHT1, OpenGL.GL_POSITION, position1); }
//public GLVertex() //{ // m_v3Position.X = 0; // m_v3Position.Y = 0; // m_v3Position.Z = 0; // m_v4Color.X = (OpenTK.Half)0; // m_v4Color.Y = (OpenTK.Half)0; // m_v4Color.Z = (OpenTK.Half)0; // m_v4Color.W = (OpenTK.Half)0; // m_v2UV.X = 0; // m_v2UV.Y = 0; //} public GLVertex(OpenTK.Vector4 a_v4Position, OpenTK.Vector4 a_v4Color, OpenTK.Vector2 a_v2UV) { m_v4Position = a_v4Position; m_v4Color = a_v4Color; m_v2UV = a_v2UV; }
protected void SavePBO(string fileName) { InitGammaTable(); OGLBuffer buffer = OutputBuffer as OGLBuffer; if (buffer == null) return; Vector4[] data = new Vector4[buffer.Width * buffer.Height]; buffer.GetDataNoAlloc<Vector4>(data); using (var bmp = new Bitmap(this.Width, this.Height)) { for (var j = 0ul; j < buffer.Height; j++) for (var i = 0ul; i < buffer.Width; i++) { bmp.SetPixel((int)i, (int)j, Vector4ToColor(data[(int)i + ((int)(buffer.Height - j - 1)) * bmp.Width])); } bmp.Save(fileName); } }
public ShaderDefinition.vec4 Convert(Vector4 v) { var v4 = new OpenTK.Vector4(v.X, v.Y, v.Z, v.W); return(v4.ToVector4F()); }
private Color Vector4ToColor(Vector4 c) { return Color.FromArgb((byte)(Radiance2PixelFloat(c.X) * 255.0f), (byte)(Radiance2PixelFloat(c.Y) * 255.0f), (byte)(Radiance2PixelFloat(c.Z) * 255.0f)); }
public OpenTK.Vector4 GetLightAmountAdjusted(Location pos, Location norm) { OpenTK.Vector4 vec = new OpenTK.Vector4(ClientUtilities.Convert(GetLightAmount(pos, norm, null)), 1.0f) * GetSunAdjust(); if (TheClient.CVars.r_fast.ValueB) { return Regularize(vec); } return RegularizeBig(vec, 5f); }
public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null) { var data = (NTRO)Resource.Blocks[BlockType.DATA]; var refMeshes = (NTROArray)data.Output["m_refMeshes"]; var materialGroups = (NTROArray)data.Output["m_materialGroups"]; for (var i = 0; i < refMeshes.Count; i++) { var refMesh = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)refMeshes[i]).Value; var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh.Name + "_c", path, currentPackage); if (newResource == null) { Console.WriteLine("unable to load mesh " + refMesh.Name); continue; } if (!newResource.Blocks.ContainsKey(BlockType.VBIB)) { Console.WriteLine("Old style model, no VBIB!"); continue; } var skinMaterials = new List <string>(); if (!string.IsNullOrEmpty(skin)) { foreach (var materialGroup2 in materialGroups) { var materialGroup = ((NTROValue <NTROStruct>)materialGroup2).Value; if (((NTROValue <string>)materialGroup["m_name"]).Value == skin) { var materials = (NTROArray)materialGroup["m_materials"]; foreach (var material in materials) { skinMaterials.Add(((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)material).Value.Name); } break; } } } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = transform, TintColor = tintColor, SkinMaterials = skinMaterials }); // TODO: Only first, again. break; } }
public void SetUniform(string name, OpenTK.Vector4 value) => GL.Uniform4(GL.GetUniformLocation(Handle, name), value);
internal StructureBspWeatherPolyhedronPlaneBlockBase(BinaryReader binaryReader) { this.plane = binaryReader.ReadVector4(); }