internal Bone(string name, int parent, ImmutableArray <int> boneControllers, Vector3f position, Quaternionf quaternion, Vector3f rotation, Vector3f positionScale, Vector3f rotationScale, Matrix4x4f poseToBone, Quaternionf alignment, int flags, int procType, int procIndex, int physicsBone, int surfacePropIdx, int contents) { Name = name; Parent = parent; BoneControllers = boneControllers; Position = position; Quaternion = quaternion; Rotation = rotation; PositionScale = positionScale; RotationScale = rotationScale; PoseToBone = poseToBone; Alignment = alignment; Flags = flags; ProcType = procType; ProcIndex = procIndex; PhysicsBone = physicsBone; SurfacePropIdx = surfacePropIdx; Contents = contents; }
protected override void OnPostRender() { Camera cam = Camera.current; if (cam == null) { return; } DrawLines.LineMode = LINE_MODE.LINES; DrawVertices.Orientation = DRAW_ORIENTATION.XY; Matrix4x4f m = Matrix4x4f.Identity; if (!MadePolygon) { base.OnPostRender(); } else { DrawPolygon(cam, polygon, Color.green, Color.yellow); if (line != null) { DrawLines.Draw(cam, line.Positions, Color.blue, m, line.Indices); DrawVertices.Draw(cam, 0.02f, line.Positions, Color.yellow, m); } } }
public void Draw(float width, float height, TimeSpan time) { float progress = time.Ticks / 10_000_000f; using (_program.Use()) { using (var context = _gpuSpace.UseBuffer()) { var transformation = Matrix4x4f.Translated(progress * 2f, 0, 0); VoxelKernel.Clear(context.Space); VoxelKernel.Sample(_gpuShape.Shape, context.Space, Matrix.From(transformation), maxDistance: 2, revert: false); VoxelKernel.Normalize(context.Space); } using (var context = _gpuSpace.UseTexture()) { _program.Transformation = GetWorldTransformation(width, height, progress); _program.Weights = context.Texture; _program.Bounds = _gpuSpace.Bounds; _box.Draw(_gpuSpace.Bounds.Length); } } }
private void OnPostRender() { Camera cam = Camera.current; if (cam == null) { return; } if (mesh == null) { return; } DrawFaces.FaceMode = FACE_MODE.TRIANGLES; DrawLines.LineMode = LINE_MODE.TRIANGLES; DrawBase.Orientation = DRAW_ORIENTATION.XY; Matrix4x4f m = Matrix4x4f.Identity; //DrawFaces.Draw(cam, positions, Color.green, m, indices); DrawLines.Draw(cam, positions, Color.blue, m, indices); //DrawVertices.Draw(cam, 0.02f, positions, Color.yellow, m); DrawLines.LineMode = LINE_MODE.LINES; DrawLines.Draw(cam, linePositions, Color.red, m, lineIndices); }
/// <summary> /// Update shadow map. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> public override void UpdateShadowMap(GraphicsContext ctx, SceneGraph shadowGraph) { CheckCurrentContext(ctx); if (shadowGraph == null) { throw new ArgumentNullException("shadowGraph"); } // Compute light matrix Matrix4x4f viewMatrix = Matrix4x4f.LookAtDirection(LocalModelView.Value.Position, (Vertex3f)Direction, Vertex3f.UnitY); // LocalModel.Multiply(LightMatrix.GetInverseMatrix()).GetInverseMatrix(); // Set light scene view shadowGraph.ProjectionMatrix = Matrix4x4f.Perspective(FalloffAngle * 2.0f, 1.0f, 0.1f, 100.0f); shadowGraph.ViewMatrix = viewMatrix; _ShadowFramebuffer.BindDraw(ctx); // Reset viewport new ViewportState(0, 0, (int)_ShadowMap.Width, (int)_ShadowMap.Height).Apply(ctx, null); _ShadowFramebuffer.Clear(ctx, ClearBufferMask.DepthBufferBit); shadowGraph.Draw(ctx, _ShadowProgram); _ShadowFramebuffer.UnbindDraw(ctx); // Cache view matrix _ShadowViewMatrix = _BiasMatrix * shadowGraph.ProjectionMatrix * viewMatrix; }
/// <summary> /// Create the corresponding <see cref="LightsState.Light"/> for this object. /// </summary> /// <returns> /// It returns the <see cref="LightsState.Light"/> equivalent to this SceneObjectLight. /// </returns> public override LightsState.Light ToLight(GraphicsContext ctx, SceneGraphContext sceneCtx) { TransformState transformState = (TransformState)sceneCtx.GraphicsStateStack.Current[TransformState.StateSetIndex]; LightsState.LightSpot light = new LightsState.LightSpot(); SetLightParameters(sceneCtx, light); Matrix4x4f worldModel = transformState.ModelView; Matrix3x3f normalMatrix = new Matrix3x3f(worldModel, 3, 3).Inverse.Transposed; light.Direction = (normalMatrix * (Vertex3f)Direction).Normalized; light.Position = (Vertex3f)(worldModel * Vertex3f.Zero); light.AttenuationFactors = AttenuationFactors; light.FallOff = new Vertex2f((float)Math.Cos(Angle.ToRadians(FalloffAngle)), FalloffExponent); // Shadow mapping if (_ShadowMap != null) { // Determined later: light.ShadowMapIndex light.ShadowMapMvp = _ShadowViewMatrix; light.ShadowMap2D = _ShadowMap; } else { light.ShadowMapIndex = -1; light.ShadowMap2D = null; } return(light); }
internal override IEnumerable <SceneObjectBatch> GetGeometries(GraphicsContext ctx, SceneGraphContext ctxScene) { if ((ctxScene.Scene.SceneFlags & SceneGraphFlags.BoundingVolumes) != 0) { GraphicsStateSet boundingVolumeState = ctxScene.GraphicsStateStack.Current.Push(); // Transform TransformState boundingVolumeModel = (TransformState)boundingVolumeState[TransformState.StateSetIndex]; float lightVolumeDepth = 100.0f; float lightVolumeSize = lightVolumeDepth * (float)Math.Tan(Angle.ToRadians(FalloffAngle)); boundingVolumeModel.ModelViewProjection = (boundingVolumeModel.ModelViewProjection * LightMatrix) * Matrix4x4f.Translated(0.0f, 0.0f, lightVolumeDepth) * Matrix4x4f.Scaled(lightVolumeSize, lightVolumeSize, lightVolumeDepth); // Uniform color ShaderUniformState uniformState = new ShaderUniformState("UniformState"); uniformState.SetUniformState("glo_UniformColor", new ColorRGBAF(1.0f, 1.0f, 0.0f, 0.5f)); boundingVolumeState.DefineState(uniformState); // Alpha blending boundingVolumeState.DefineState(BlendState.AlphaBlending); yield return(new SceneObjectBatch( _BoundingVolumeArrays, boundingVolumeState, _BoundingVolumeProgram )); } yield break; }
public MasterRenderer(Camera camera, Loader loader, DirectionalLight sun, int width, int height) { Gl.Enable(EnableCap.DepthTest); this.clientWidth = width; this.clientHeight = height; this.projectionMatrix = Maths.CreateProjectionMatrix(FOV, AspectRatio, NEAR_PLANE, FAR_PLANE); //Entities this.entityShader = new StaticShader(); this.entityRenderer = new EntityRenderer(entityShader, width, height, this.projectionMatrix); this.entities = new Dictionary <TextureModel, List <Entity> >(); //Skybox this.skyboxRenderer = new SkyboxRenderer(loader, this.projectionMatrix); //Shadow this.shadowDepthShader = new ShadowDepthShader(); this.shadowDepthFrameBuffer = new ShadowDepthFrameBuffer(); this.shadowRenderer = new ShadowRenderer(sun, shadowDepthShader, shadowDepthFrameBuffer); //Terrain this.terrainShader = new TerrainShader(); this.terrainRenderer = new TerrainRenderer(this.terrainShader, this.projectionMatrix, this.shadowRenderer); this.terrainList = new List <Terrain>(); }
public MousePicker(Camera cam, Matrix4x4f projection, Terrain terrain) { this.camera = cam; this.projectionMatrix = projection; this.viewMatrix = Maths.CreateViewMatrix(camera); this.terrain = terrain; }
public void LoadViewMatrix(Camera camera) { Matrix4x4f viewMatrix = Maths.CreateViewMatrix(camera); base.LoadMatrix(this.location_viewMatrix, viewMatrix); base.LoadVector3(this.location_cameraPosition, camera.Position); }
public void SetMatrix(string name, Matrix4x4f value) { if (GetUniformLocation(name, out int loc)) { Gl.ProgramUniformMatrix4f(Id, loc, 1, false, value); } }
internal Bone(string name, int parent, ImmutableArray<int> boneControllers, Vector3f position, Quaternionf quaternion, Vector3f rotation, Vector3f positionScale, Vector3f rotationScale, Matrix4x4f poseToBone, Quaternionf alignment, int flags, int procType, int procIndex, int physicsBone, int surfacePropIdx, int contents) { Name = name; Parent = parent; BoneControllers = boneControllers; Position = position; Quaternion = quaternion; Rotation = rotation; PositionScale = positionScale; RotationScale = rotationScale; PoseToBone = poseToBone; Alignment = alignment; Flags = flags; ProcType = procType; ProcIndex = procIndex; PhysicsBone = physicsBone; SurfacePropIdx = surfacePropIdx; Contents = contents; }
protected virtual void OnPostRender() { Camera cam = Camera.current; if (cam == null) { return; } if (Points == null) { return; } if (Indices == null) { return; } Matrix4x4f m = Matrix4x4f.Identity; DrawLines.LineMode = LINE_MODE.LINES; DrawVertices.Orientation = DRAW_ORIENTATION.XY; DrawLines.Draw(cam, Points, LineColor, m, Indices); DrawVertices.Draw(cam, 0.02f, Points, Color.yellow, m); }
private void PrepareInstance(Entity entity) { Matrix4x4f transformationMatrix = Maths.CreateTransformationMatrix(entity.Position, entity.RotationX, entity.RotationY, entity.RotationZ, entity.Scale); this.shader.LoadTransformationMatrix(transformationMatrix); this.shader.LoadAtlasInfo(entity.TextureModel.Texture.NumberOfRows, new Vertex2f(entity.GetTextureOffsetX(), entity.GetTextureOffsetY())); }
public void Render(Matrix4x4f projViewMatrix) { foreach (Models.Model model in models) { model.Render(projViewMatrix); } }
public FluidBody3d(ParticleSource source, float radius, float density, Matrix4x4f RTS) : base(source.NumParticles, radius, 1.0f) { Density = density; Viscosity = 0.02f; Dampning = 1; float d = ParticleDiameter; ParticleMass = 0.8f * d * d * d * Density; CreateParticles(source, RTS); float cellSize = ParticleRadius * 4.0f; Kernel = new CubicKernel3dGPU(cellSize); NeighboursSearcher = new ParticleNeighboursSearcherGPU(cellSize); Lambda = new float[NumParticles]; GPULambda = new ComputeBuffer <float>(NumParticles); Densities = new float[NumParticles]; GPUDensities = new ComputeBuffer <float>(NumParticles); InitCurrentShader(); InitShaderConsts(); Kernel.InitCubicKernel3dGPU(CurrentShader); }
public EntityRenderer(StaticShader shader, int width, int height, Matrix4x4f projectionMatrix) { this.shader = shader; this.shader.Start(); this.shader.LoadProjectionMatrix(projectionMatrix); this.shader.Stop(); }
public static uint RenderToCubemap(Shader shader, int resolution, Action preRender) { var cube = new Cube(); var captureFbo = Gl.GenFramebuffer(); Gl.BindFramebuffer(FramebufferTarget.Framebuffer, captureFbo); var colorTexture = Gl.GenTexture(); Gl.BindTexture(TextureTarget.Texture2d, colorTexture); Gl.TexImage2D(TextureTarget.Texture2d, 0, InternalFormat.Srgb, Constants.renderWidth, Constants.renderHeight, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero); Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapNearest); Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); Gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2d, colorTexture, 0); var envCubemap = Gl.GenTexture(); Gl.BindTexture(TextureTarget.TextureCubeMap, envCubemap); for (int i = 0; i < 6; ++i) { Gl.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, InternalFormat.Srgb, resolution, resolution, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero); } Gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); Gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); Gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); Gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); Gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge); var projMatrix = Matrix4x4f.Perspective(90f, 1.0f, 0.1f, 10.0f); var viewMatrices = new Matrix4x4f[] { Matrix4x4f.LookAt(new Vertex3f(0f, 0f, 0f), new Vertex3f(1f, 0f, 0f), new Vertex3f(0f, -1f, 0f)), Matrix4x4f.LookAt(new Vertex3f(0f, 0f, 0f), new Vertex3f(-1f, 0f, 0f), new Vertex3f(0f, -1f, 0f)), Matrix4x4f.LookAt(new Vertex3f(0f, 0f, 0f), new Vertex3f(0f, 1f, 0f), new Vertex3f(0f, 0f, 1f)), Matrix4x4f.LookAt(new Vertex3f(0f, 0f, 0f), new Vertex3f(0f, -1f, 0f), new Vertex3f(0f, 0f, -1f)), Matrix4x4f.LookAt(new Vertex3f(0f, 0f, 0f), new Vertex3f(0f, 0f, 1f), new Vertex3f(0f, -1f, 0f)), Matrix4x4f.LookAt(new Vertex3f(0f, 0f, 0f), new Vertex3f(0f, 0f, -1f), new Vertex3f(0f, -1f, 0f)), }; shader.Use(); preRender.Invoke(); shader.SetMatrix("projectionMatrix", projMatrix); Gl.Viewport(0, 0, resolution, resolution); Gl.BindFramebuffer(FramebufferTarget.Framebuffer, captureFbo); for (int i = 0; i < 6; ++i) { shader.SetMatrix("viewMatrix", viewMatrices[i]); Gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureCubeMapPositiveX + i, envCubemap, 0); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); cube.Draw(); } Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0); return(envCubemap); }
public void Render(List <GUITexture> guiList) { if (guiList == null || guiList.Count > 0 == false) { return; } this.shader.Start(); Gl.BindVertexArray(this.quadModel.VaoID); Gl.EnableVertexAttribArray(0);// Position Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Disable(EnableCap.DepthTest); for (int i = 0; i < guiList.Count; i++) { Gl.ActiveTexture(TextureUnit.Texture0); Gl.BindTexture(TextureTarget.Texture2d, guiList[i].TextureID); Matrix4x4f transformationMatrix = Maths.CreateTransformationMatrix(guiList[i].Position, guiList[i].Scale); this.shader.LoadTransformationMatrix(transformationMatrix); Gl.DrawArrays(PrimitiveType.TriangleStrip, 0, this.quadModel.VertexCount); } Gl.Enable(EnableCap.DepthTest); Gl.Disable(EnableCap.Blend); Gl.DisableVertexAttribArray(0); Gl.BindVertexArray(0); this.shader.Stop(); }
public void KhronosApi_GenericWrapperByRef() { const int callCount = 1 << 26; Stopwatch sw; Matrix4x4f arg = Matrix4x4f.Identity; sw = Stopwatch.StartNew(); for (int i = 0; i < callCount; i++) { if (GenericArgByRef(ref arg)) { break; } } sw.Stop(); Console.WriteLine("GenericArgByRef: {0:0.000E0} calls/sec", (float)(callCount / (sw.Elapsed.TotalMilliseconds / 1000.0))); sw = Stopwatch.StartNew(); for (int i = 0; i < callCount; i++) { if (GenericArgByValue(arg)) { break; } } sw.Stop(); Console.WriteLine("GenericArgByValue: {0:0.000E0} calls/sec", (float)(callCount / (sw.Elapsed.TotalMilliseconds / 1000.0))); }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.ClearColor(1.0f, 0.0f, 0.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.ProjectionMatrix = Matrix4x4f.Perspective(45.0f, senderAspectRatio, 0.1f, 100.0f); // _CubeScene.CurrentView.LocalModelView = Matrix4x4f.Translated(0.0f, 0.0f, 10.0f); //_CubeScene.CurrentView.LocalModelView = // Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f) * // Matrix4x4f.RotatedY(_ViewAzimuth) * // Matrix4x4f.RotatedX(_ViewElevation) * // Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever); //_CubeScene.CurrentView.LocalModelView = // Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever) * // Matrix4x4f.RotatedX(_ViewElevation) * // Matrix4x4f.RotatedY(_ViewAzimuth) * // Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.UpdateViewMatrix(); _CubeScene.Draw(_Context); }
private SceneObjectGeometry CreateSphere(string material) { SceneObjectGeometry sphereGeometry = new SceneObjectGeometry("Sphere"); sphereGeometry.ObjectState.DefineState(new CullFaceState(FrontFaceDirection.Ccw, CullFaceMode.Back)); sphereGeometry.ObjectState.DefineState(new TransformState()); sphereGeometry.LocalModelView = Matrix4x4f.Translated(0.0f, 4.0f, 0.0f); sphereGeometry.VertexArray = VertexArrays.CreateSphere(4.0f, 32, 32); ArrayBuffer <Vertex2f> texCoordBuffer = new ArrayBuffer <Vertex2f>(); texCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(texCoordBuffer, VertexArraySemantic.TexCoord); ArrayBuffer <Vertex3f> tanCoordBuffer = new ArrayBuffer <Vertex3f>(); tanCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(tanCoordBuffer, VertexArraySemantic.Tangent); ArrayBuffer <Vertex3f> bitanCoordBuffer = new ArrayBuffer <Vertex3f>(); bitanCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(bitanCoordBuffer, VertexArraySemantic.Bitangent); sphereGeometry.VertexArray.GenerateTexCoords(new VertexArrayTexGen.Sphere()); sphereGeometry.VertexArray.GenerateTangents(); sphereGeometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment"); SetSphereMaterial(sphereGeometry, material); return(sphereGeometry); }
/// <summary> /// Draw a character sequence. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for drawing. /// </param> /// <param name="modelview"> /// The <see cref="Matrix4x4f"/> the model-view-projection matrix for the first character of <paramref name="s"/>. /// </param> /// <param name="color"> /// The <see cref="ColorRGBAF"/> that specifies the glyph color. /// </param> /// <param name="s"> /// A <see cref="String"/> that specifies the characters for be drawn. /// </param> public override void DrawString(GraphicsContext ctx, Matrix4x4f modelview, ColorRGBAF color, string s) { List <GlyphModelType> glyphsInstances = GetGlyphsInstances(modelview, s); UpdateGlyphBuffer(ctx, glyphsInstances); DrawStringCore(ctx, _FontTexture, color, glyphsInstances); }
public static Matrix4x4f CreateTransformationMatrix(Vertex2f translation, Vertex2f scale) { Matrix4x4f matrix = new Matrix4x4f(IdentityMatrix4x4); matrix.Translate(translation.x, translation.y, 0); matrix.Scale(scale.x, scale.y, 1f); return(matrix); }
public FluidBoundary3d(ParticleSource source, double radius, double density, Matrix4x4f RTS) { ParticleRadius = radius; Density = density; CreateParticles(source, RTS); CreateBoundryPsi(); }
/// <summary> /// Draw a character sequence. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for drawing. /// </param> /// <param name="modelview"> /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>. /// </param> /// <param name="color"> /// The <see cref="ColorRGBAF"/> that specifies the glyph color. /// </param> /// <param name="s"> /// A <see cref="String"/> that specifies the characters for be drawn. /// </param> public override void DrawString(GraphicsContext ctx, Matrix4x4 modelview, ColorRGBAF color, string s) { ModelMatrix charModel = new ModelMatrix(modelview); ctx.Bind(_FontProgram); // Set uniforms _FontProgram.SetUniform(ctx, "glo_UniformColor", color); _FontProgram.SetUniform(ctx, "glo_FontGlyph", _FontTexture); // Set instances char[] fontChars = s.ToCharArray(); uint instances = 0; _GlyphInstances.Map(ctx, BufferAccessARB.WriteOnly); try { for (int i = 0; i < fontChars.Length; i++) { Glyph glyph; if (_GlyphDb.TryGetValue(fontChars[i], out glyph) == false) { continue; } // Set instance information Matrix4x4f modelViewProjection = new Matrix4x4f( new Vertex4f(charModel.GetColumn(0)), new Vertex4f(charModel.GetColumn(1)), new Vertex4f(charModel.GetColumn(2)), new Vertex4f(charModel.GetColumn(3)) ); Vertex3f glyphVertexParams = new Vertex3f( glyph.GlyphSize.Width, glyph.GlyphSize.Height, glyph.Layer ); Vertex2f glyphTexParams = new Vertex2f( glyph.TexScale.Width, glyph.TexScale.Height ); _GlyphInstances.SetElement(modelViewProjection, instances, 0); _GlyphInstances.SetElement(glyphVertexParams, instances, 1); _GlyphInstances.SetElement(glyphTexParams, instances, 2); // Count the instance instances++; // Move next charModel.Translate(glyph.GlyphSize.Width, 0.0f); } } finally { _GlyphInstances.Unmap(ctx); } // Rasterize it using (State.BlendState stateBlend = State.BlendState.AlphaBlending) { stateBlend.ApplyState(ctx, _FontProgram); _VertexArrays.DrawInstanced(ctx, _FontProgram, instances); } }
public void GetColumn() { Matrix4x4f m = Indexed4x4(); Assert.AreEqual(new Vector4f(0, 1, 2, 3), m.GetColumn(0)); Assert.AreEqual(new Vector4f(4, 5, 6, 7), m.GetColumn(1)); Assert.AreEqual(new Vector4f(8, 9, 10, 11), m.GetColumn(2)); Assert.AreEqual(new Vector4f(12, 13, 14, 15), m.GetColumn(3)); }
/// <summary> /// Sets the value of the uniform with the specified <paramref name="name"/> /// to the specified <paramref name="matrix"/>. /// </summary> /// <param name="name">The name of the uniform to set.</param> /// <param name="matrix">The matrix to set.</param> public void SetMatrix4x4f(string name, Matrix4x4f matrix) { int location = Gl.GetUniformLocation(_program, name); if (location > -1) { Gl.UniformMatrix4f(location, 1, false, matrix); } }
public void TryInverse() { Matrix4x4f m = Random4x4(0); Matrix4x4f inverse = Matrix4x4f.Identity; m.TryInverse(ref inverse); Assert.IsTrue((inverse * Random4x4(0)).EqualsWithError(Matrix4x4f.Identity, 1e-6f)); }
/// <summary> /// Static constructor. /// </summary> static SceneObjectLight() { _BiasMatrix = new Matrix4x4f(new[] { 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, }); }
public void GetRow() { Matrix4x4f m = Indexed4x4(); Assert.AreEqual(new Vector4f(0, 4, 8, 12), m.GetRow(0)); Assert.AreEqual(new Vector4f(1, 5, 9, 13), m.GetRow(1)); Assert.AreEqual(new Vector4f(2, 6, 10, 14), m.GetRow(2)); Assert.AreEqual(new Vector4f(3, 7, 11, 15), m.GetRow(3)); }
ImmutableArray<Bone> LoadBones(Ibasa.IO.BinaryReader reader, int count) { long offset = reader.BaseStream.Position; Bone[] bones = new Bone[count]; for (int i = 0; i < count; ++i) { reader.BaseStream.Position = offset; long nameOffset = offset + reader.ReadInt32(); int parent = reader.ReadInt32(); ImmutableArray<int> boneControllers = new ImmutableArray<int>(new int[] { reader.ReadInt32(),reader.ReadInt32(),reader.ReadInt32(), reader.ReadInt32(),reader.ReadInt32(),reader.ReadInt32()}); Vector3f position = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Quaternionf quaternion = new Quaternionf(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vector3f rotation = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vector3f positionScale = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vector3f rotationScale = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Matrix4x4f poseToBone = new Matrix4x4f( reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), 0, 0, 0, 1); Quaternionf alignment = new Quaternionf(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); int flags = reader.ReadInt32(); int procType = reader.ReadInt32(); int procIndex = reader.ReadInt32(); int physicsBone = reader.ReadInt32(); int surfacePropIdx = reader.ReadInt32(); int contents = reader.ReadInt32(); reader.Seek(8 * 4, SeekOrigin.Current); //skip 8 ints offset = reader.BaseStream.Position; reader.BaseStream.Position = nameOffset; string name = LoadString(reader); bones[i] = new Bone(name, parent, boneControllers, position, quaternion, rotation, positionScale, rotationScale, poseToBone, alignment, flags, procType, procIndex, physicsBone, surfacePropIdx, contents); } return new ImmutableArray<Bone>(bones); }