private void UpdateSenzorToCamera() { // - translate by (-0.5, -aspectRatio * 0.5) // - scale by (width, height, 1) // - translate by (shiftX, shiftY, distanceZ) // - [tilt around X by tiltX, ...] var matrix = Matrix4d.CreateTranslation(-0.5, AspectRatio * -0.5, 0); matrix = Matrix4d.Mult(matrix, Matrix4d.Scale(Width, Width, 1)); matrix = Matrix4d.Mult(matrix, Matrix4d.CreateTranslation(Shift)); TiltMatrix = Matrix4d.Identity; if (Tilt.X != 0) { TiltMatrix = Matrix4d.CreateRotationX(Tilt.X); } if (Tilt.Y != 0) { TiltMatrix = Matrix4d.Mult(TiltMatrix, Matrix4d.CreateRotationY(Tilt.Y)); } if (Tilt.Z != 0) { TiltMatrix = Matrix4d.Mult(TiltMatrix, Matrix4d.CreateRotationZ(Tilt.Z)); } matrix = Matrix4d.Mult(matrix, TiltMatrix); SenzorToCamera = matrix; }
protected SortedSet <Collision> Intersections() { var ray = Camera.GetMouseRay(); var hits = new SortedSet <Collision>(); foreach (var gui_element in gui_elements) { var model_matrix = Matrix4d.Scale(1.0 / Camera.Window.ClientRectangle.Width, 1.0 / Camera.Window.ClientRectangle.Height, 1.0) * gui_element.ModelMatrix * Matrix4d.CreateTranslation(-0.5, -0.5, 0.0) * Matrix4d.Scale(2.0, 2.0, 1.0) * RenderContext.InvertedProjection; var hit = gui_element.Model.Mesh().BoundingBox.At(ref model_matrix).Collides(ref ray); if (null == hit) { continue; } hit.Object0 = ray; hit.Object1 = gui_element; hits.Add(hit); } return(hits); }
public virtual void Draw(Vector3d location, Quaterniond rotation) { Matrix4d trans; Matrix4d rot; Matrix4d sca; Matrix4d temp; Vector3d axis; double angle; // Translate and rotate stuff. trans = Matrix4d.CreateTranslation(location); rotation.ToAxisAngle(out axis, out angle); Matrix4d.CreateFromAxisAngle(axis, angle, out rot); sca = Matrix4d.Scale(scale.X, 1, scale.Y); temp = Matrix4d.Mult(Graphics.Modelview, trans); temp = Matrix4d.Mult(sca, Matrix4d.Mult(rot, temp)); GL.PushMatrix(); GL.LoadMatrix(ref temp); //Console.WriteLine("Matrix'd"); // Do drawing stuff. //GL.ClientActiveTexture(TextureUnit.Texture0); //GL.ActiveTexture(TextureUnit.Texture1); //GL.BindTexture(TextureTarget.Texture2D, tex); //int loc = GL.GetUniformLocation(Graphics.CurrentShader, "tex1"); //GL.Uniform1(loc, 1); //Console.WriteLine("Texture'd {0}", tex); material.Draw(); geometry.Draw(); GL.PopMatrix(); }
public override void Render() { if (!Visible) { return; } TheClient.SetEnts(); BEPUutilities.RigidTransform rt = new BEPUutilities.RigidTransform(GetPosition().ToBVector(), GetOrientation()); BEPUutilities.Vector3 bmin; BEPUutilities.Vector3 bmax; BEPUutilities.RigidTransform.Transform(ref ModelMin, ref rt, out bmin); BEPUutilities.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 = (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(); } model.Draw(); // TODO: Animation? }
/// <summary> /// Renders a billboard along a line. /// </summary> /// <param name="pos">Start position.</param> /// <param name="p2">End position.</param> /// <param name="width">Width of the line.</param> /// <param name="facing">Facing target.</param> /// <param name="view">Relevant view.</param> public void RenderBilboardLine(Location pos, Location p2, float width, Location facing, View3D view) { Location center = (pos + p2) * 0.5; double len = (center - facing).Length(); Location lookdir = (center - facing) / len; double len2 = (p2 - pos).Length(); if (len < 0.001 || len2 < 0.001) { return; } Location updir = (p2 - pos) / len2; Location right = updir.CrossProduct(lookdir); Matrix4d mat = Matrix4d.CreateTranslation(-0.5f, -0.5f, 0f) * Matrix4d.Scale((float)len2 * 0.5f, width, 1f); Matrix4d m2 = new Matrix4d(right.X, updir.X, lookdir.X, center.X, right.Y, updir.Y, lookdir.Y, center.Y, right.Z, updir.Z, lookdir.Z, center.Z, 0, 0, 0, 1); m2.Transpose(); mat *= m2; view.SetMatrix(2, mat); GL.BindVertexArray(Square._VAO); GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero); GL.BindVertexArray(0); }
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 virtual void Draw(Vector3d location, Quaterniond rotation) { Matrix4d trans; Matrix4d rot; Matrix4d sca; Matrix4d temp; Vector3d axis; double angle; //Console.WriteLine("DDDDrawing at {0},{1},{2}", location.X, location.Y, location.Z); // Translate and rotate stuff. trans = Matrix4d.CreateTranslation(location); rotation.ToAxisAngle(out axis, out angle); Matrix4d.CreateFromAxisAngle(axis, angle, out rot); sca = Matrix4d.Scale(scale.X, 1, scale.Y); temp = Matrix4d.Mult(Graphics.Modelview, trans); temp = Matrix4d.Mult(sca, Matrix4d.Mult(rot, temp)); //Console.WriteLine("MMMMatrix:\n{0}", temp); GL.PushMatrix(); GL.LoadMatrix(ref temp); //Console.WriteLine("Matrix'd"); // Do drawing stuff. GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, frames[animFrame]); geometry.Draw(); GL.PopMatrix(); }
public void PrepareGrass(MTerrainTile tile) { MTerrainTile Tile = tile; Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Quaterniond.FromEulerAngles(tile.transform.Up())); float numxinterps = LOD0Size / Tile.x_res; float numzinterps = LOD0Size / Tile.z_res; for (int x = 0; x < LOD0Size; x++) { for (int z = 0; z < LOD0Size; z++) { Vector3d PlantingPos = new Vector3d((x / numxinterps), 0, (z / numzinterps)); //PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos); //double y = tile.ElevationAtPoint(x / numxinterps, z / numzinterps); //PlantingPos = new Vector3d(x, y, z); PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos); Matrix4d TreeScale = Matrix4d.Scale(10, 10, 10); Matrix4d TreePosition = Matrix4d.CreateTranslation(PlantingPos); Matrix4 final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition); Grassmats[x, z] = final; } } IsComplete = true; Console.WriteLine("Grass Planted:" + Tile.TileX + "," + Tile.TileY); }
public Matrix4d GetMatrix() { Matrix4d matrix = Matrix4d.CreateRotationY(Utils.DEGREES_TO_RADIANS(this.Rotation)); matrix = Matrix4d.Mult(matrix, Matrix4d.CreateTranslation(Translation.X, 0, Translation.Y)); matrix = Matrix4d.Mult(matrix, Matrix4d.Scale(Scale, 1f, Scale)); return(matrix); }
private void PreviewPanel_Paint(object sender, PaintEventArgs e) { //Graphics g = e.Graphics; using (Bitmap bmp = new Bitmap(PreviewPanel.Width, PreviewPanel.Height)) { using (Graphics g = Graphics.FromImage(bmp)) { g.Clip = new Region(); using (SolidBrush b = new SolidBrush(PreviewPanel.BackColor)) g.FillRectangle(b, 0, 0, PreviewPanel.Width, PreviewPanel.Height); if (ScanInfo != null) { try { ScanLine line = null; LaserCorrection corr = null; double size = ScanInfo.Size() * 0.66f; double factor = Math.Min(PreviewPanel.Width, PreviewPanel.Height) / size; Matrix4d baseMatrix = Matrix4d.Scale(factor); PointF center = new PointF(PreviewPanel.Width / 2, PreviewPanel.Height / 2); DrawGrid(g, center, (float)factor); int currentLaser = CurrentLaserIndex; List <ScanLine> selectedLaserLine = new List <ScanLine>(); for (int i = 0; i < ScanInfo.Count; i++) { line = ScanInfo[i]; corr = new LaserCorrection(); corr.LoadFromSettings(line.LaserID); bool selected = currentLaser == line.LaserID; if (!selected) { DrawScanLine(g, center, factor, line, corr, false); } else { selectedLaserLine.Add(line); } } corr = new LaserCorrection(); corr.LoadFromSettings(selectedLaserLine[Math.Max(0, currentLaser)].LaserID); corr.Apply(Drag); for (int i = 0; i < selectedLaserLine.Count; i++) { DrawScanLine(g, center, factor, selectedLaserLine[i], corr, true); } } catch { } } } e.Graphics.Clip = new Region(); e.Graphics.DrawImageUnscaled(bmp, new Point(0, 0)); } }
public void PlantPatch(Barycentric bary, int BladeCount = 4096, double Area = 1.1, double MaxHeight = 1) { double sq2 = Math.Sqrt(BladeCount); Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation()); Matrix4d TreePosition; Matrix4 final; Matrix4d TreeScale; Vector3d PlantingPos = new Vector3d(); int bposx = (int)(Tile.x_res * (1 - bary.u)); int bposz = (int)(Tile.z_res * (bary.v)); // Tile.Biome.SetPixel(bposx, bposz, new float[] { 0, 1, 0, 1 }); for (int x = (int)-sq2; x < sq2; x++) { for (int z = (int)-sq2; z < sq2; z++) { bposx = (int)(Tile.x_res * (1 - bary.u)) - x; bposz = (int)(Tile.z_res * (bary.v)) - z; int t = Tile._biome.GetBiomeAt(bposx, bposz); if ((t != MBiome.GRASS) && (t != MBiome.TREES) && (t != MBiome.TREES2) && (t != MBiome.WATER)) { continue; } PlantingPos.X = (int)(Tile.x_res * (1 - bary.u)) - x * 0.05 * Area; PlantingPos.Y = 0; PlantingPos.Z = (int)(Tile.z_res * (bary.v)) - z * 0.05 * Area; double yv = (MPerlin.Noise(PlantingPos.X, PlantingPos.Z) * 0.4) + (MPerlin.Noise(PlantingPos.X * 1.1, PlantingPos.Z * 1.1) * 0.4) ; //if (yv < 0.01) continue; TreeScale = Matrix4d.Scale(0.05 + 0.06 * yv, 0.01 + Math.Abs(yv) * 0.15 * MaxHeight, 0.05 + 0.06 * yv); PlantingPos.X += MPerlin.Noise(PlantingPos.X * 4.0, 0, PlantingPos.Z * 2.0) * 1.1; PlantingPos.Z += MPerlin.Noise(PlantingPos.X * 4.0, 0, PlantingPos.Z * 2.0) * 1.1; PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos); TreePosition = Matrix4d.CreateTranslation(PlantingPos); final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition); if (TotalInstances < Settings.MaxGrassPerTerrain) { mats[TotalInstances] = final; TotalInstances++; } } } }
public static Matrix4d CreateTransformationMatrix(Vector3d translation, double xScale, double yScale) { Matrix4d t1 = Matrix4d.CreateTranslation(translation); Matrix4d s1 = Matrix4d.Scale(xScale, yScale, 0); Matrix4d transformationMatrix = s1 * t1;//Matrix4.Transpose(Matrix4.Transpose(t1) * s1); return(transformationMatrix); }
public Matrix4d GetMatrix() { Matrix4d model = Matrix4d.Identity; model = Matrix4d.Scale(Scale) * Matrix4d.CreateFromQuaternion(Rotation * RotationOffset) * Matrix4d.CreateTranslation(Position); return(model); }
private void UpdateObjectToWorld() { // - translate by (-0.5, -aspectRatio * 0.5) // - scale by (width, height, 1) // - translate by origin var matrix = Matrix4d.CreateTranslation(-0.5, AspectRatio * -0.5, 0); matrix = Matrix4d.Mult(matrix, Matrix4d.Scale(Width, Width, 1)); matrix = Matrix4d.Mult(matrix, Matrix4d.CreateTranslation(Plane.Origin)); ObjectToWorld = matrix; }
public override void Render() { TheClient.SetEnts(); TheClient.Textures.White.Bind(); Matrix4d mat = Matrix4d.Scale(0.05f, 0.2f, 0.05f) * GetTransformationMatrix(); TheClient.MainWorldView.SetMatrix(2, mat); TheClient.Rendering.SetColor(GColor); model.Draw(); TheClient.Rendering.SetColor(Color4.White); }
/// <summary> /// Renders a line box. /// </summary> public void RenderLineBox(Location min, Location max, Matrix4d?rot = null) { Engine.White.Bind(); Location halfsize = (max - min) / 2; Matrix4d mat = Matrix4d.Scale(ClientUtilities.ConvertD(halfsize)) * (rot != null && rot.HasValue ? rot.Value : Matrix4d.Identity) * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(min + halfsize)); Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference! GL.BindVertexArray(Box._VAO); GL.DrawElements(PrimitiveType.Lines, 24, DrawElementsType.UnsignedInt, IntPtr.Zero); }
/// <summary> /// Render the entity as seen normally, in 3D. /// </summary> /// <param name="context">The render context.</param> public override void RenderStandard(RenderContext context) { if (DiffuseTexture != null) { GL.ActiveTexture(TextureUnit.Texture0); DiffuseTexture.Bind(); } context.Engine.Rendering.SetColor(Color4F.White, context.Engine.MainView); Matrix4d mat = Matrix4d.Scale(Scale.ToOpenTK3D()) * Matrix4d.CreateFromQuaternion(RenderOrientation.ToOpenTKDoubles()) * Matrix4d.CreateTranslation(RenderAt.ToOpenTK3D()); context.Engine.MainView.SetMatrix(ShaderLocations.Common.WORLD, mat); Rend.Render(context, true); }
/// <summary> /// Render a cylinder between two points. /// </summary> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="width">The width of the cylinder.</param> public void RenderCylinder(Location start, Location end, float width) { float len = (float)(end - start).Length(); Location vecang = Utilities.VectorToAngles(start - end); Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * Utilities.PI180)) * Matrix4d.Scale(len, width, width) * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(start)); Client.Central.MainWorldView.SetMatrix(2, mat); Client.Central.Models.Cylinder.Draw(); // TODO: Models reference in constructor - or client reference? }
public void PlaceInstances(Vector3d Anchorpoint) { //DistanceThreshold = tile.DistanceThreshold; this.transform.Position = Anchorpoint; Random ran = new Random(1234); Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation()); int i = 0; for (int z = 0; z < 30; z++) { for (int x = 0; x < 30; x++) { if (i >= MaxInstances) { break; } //Vector3d pos = new Vector3d(1000 * ran.NextDouble(), 200 * ran.NextDouble(), 1000 * ran.NextDouble()); Vector3d pos = MassiveTools.RandomPointInSphere(Vector3d.Zero, 1000, ran); //Vector3d PlantingPos = planet.GetNearestPointOnSphere(SeedPos + Treepos, 0) - SeedPos; double scale = MinSize + ran.NextDouble() * (MaxSize - MinSize); Matrix4d TreeScale = Matrix4d.Scale(scale, scale, scale); Matrix4d TreePosition = Matrix4d.CreateTranslation(pos); TreeRotation = Matrix4d.CreateFromQuaternion( Quaterniond.FromEulerAngles( ran.NextDouble(), ran.NextDouble(), ran.NextDouble())); //find point at y with raycast Matrix4 final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition); mats[i] = final; i++; } } TotalInstances = i; //null out the remainder for (int j = TotalInstances; j < MaxInstances; j++) { Matrix4 final = Matrix4.Identity; mats[j] = final; } Planted = false; }
/// <summary> /// Render a line between two points. /// </summary> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> public void RenderLine(Location start, Location end) { // TODO: Efficiency! float len = (float)(end - start).Length(); Location vecang = Utilities.VectorToAngles(start - end); Matrix4d mat = Matrix4d.Scale(len, 1, 1) * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(start)); Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference! GL.BindVertexArray(Line._VAO); GL.DrawElements(PrimitiveType.Lines, 2, DrawElementsType.UnsignedInt, IntPtr.Zero); }
public void Render(double delta_time) { foreach (var gui_element in gui_elements) { RenderContext.Model = Matrix4d.Scale(1.0 / Camera.Window.ClientRectangle.Width, 1.0 / Camera.Window.ClientRectangle.Height, 1.0) * gui_element.ModelMatrix * Matrix4d.CreateTranslation(-0.5, -0.5, 0.0) * Matrix4d.Scale(2.0, 2.0, 1.0) * RenderContext.InvertedProjection; gui_element.Model.Program.UniformLocations["in_ModelViewProjection"].Set(RenderContext.ProjectionViewModel); gui_element.Render(delta_time); } }
/// <summary> /// Render a cylinder between two points. /// </summary> /// <param name="context">The sourcing render context.</param> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="width">The width of the cylinder.</param> /// <param name="view">The relevant view.</param> public void RenderCylinder(RenderContext context, Location start, Location end, float width, View3D view) { float len = (float)(end - start).Length(); Location vecang = MathUtilities.VectorToAngles(start - end); vecang.Yaw += 180; Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * MathUtilities.PI180)) * Matrix4d.Scale(len, width, width) * Matrix4d.CreateRotationY((float)(vecang.Y * MathUtilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * MathUtilities.PI180)) * Matrix4d.CreateTranslation(start.ToOpenTK3D()); view.SetMatrix(2, mat); Models.Cylinder.Draw(context); }
/// <summary> /// Render a cylinder between two points. /// </summary> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="width">The width of the cylinder.</param> /// <param name="view">The relevant view.</param> public void RenderCylinder(Location start, Location end, float width, View3D view) { float len = (float)(end - start).Length(); Location vecang = Utilities.VectorToAngles(start - end); vecang.Yaw += 180; Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * Utilities.PI180)) * Matrix4d.Scale(len, width, width) * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(start.ToOpenTK3D()); view.SetMatrix(2, mat); Models.Cylinder.Draw(); // TODO: Models reference in constructor - or client reference? }
public static void TestScene(IRayScene sc, string param) { Debug.Assert(sc != null); // CSG scene: CSGInnerNode root = new CSGInnerNode(SetOperation.Union); root.SetAttribute(PropertyName.REFLECTANCE_MODEL, new PhongModel()); root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 0.6, 0.0, 0.0 }, 0.15, 0.8, 0.15, 16)); sc.Intersectable = root; // Background color: sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 }; // Camera: sc.Camera = new StaticCamera(new Vector3d(0.7, 3.0, -10.0), new Vector3d(0.0, -0.2, 1.0), 50.0); // Light sources: sc.Sources = new LinkedList <ILightSource>(); sc.Sources.Add(new AmbientLightSource(0.8)); sc.Sources.Add(new PointLightSource(new Vector3d(-5.0, 3.0, -3.0), 1.0)); // --- NODE DEFINITIONS ---------------------------------------------------- // Base plane Plane pl = new Plane(); pl.SetAttribute(PropertyName.COLOR, new double[] { 0.0, 0.2, 0.0 }); pl.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(0.5, 0.5, new double[] { 1.0, 1.0, 1.0 })); root.InsertChild(pl, Matrix4d.RotateX(-MathHelper.PiOver2) * Matrix4d.CreateTranslation(0.0, -1.0, 0.0)); // Cylinders Cylinder c = new Cylinder(); root.InsertChild(c, Matrix4d.RotateX(MathHelper.PiOver2) * Matrix4d.CreateTranslation(-2.1, 0.0, 1.0)); c = new Cylinder(); c.SetAttribute(PropertyName.COLOR, new double[] { 0.2, 0.0, 0.7 }); c.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(12.0, 1.0, new double[] { 0.0, 0.0, 0.3 })); root.InsertChild(c, Matrix4d.RotateY(-0.4) * Matrix4d.CreateTranslation(1.0, 0.0, 1.0)); c = new Cylinder(0.0, 100.0); c.SetAttribute(PropertyName.COLOR, new double[] { 0.1, 0.7, 0.0 }); root.InsertChild(c, Matrix4d.RotateY(0.2) * Matrix4d.CreateTranslation(5.0, 0.3, 4.0)); c = new Cylinder(-0.5, 0.5); c.SetAttribute(PropertyName.COLOR, new double[] { 0.8, 0.6, 0.0 }); root.InsertChild(c, Matrix4d.Scale(2.0) * Matrix4d.RotateX(1.2) * Matrix4d.CreateTranslation(2.0, 1.8, 16.0)); }
/// <summary> /// Render a line between two points. /// </summary> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="view">The relevant view.</param> public void RenderLine(Location start, Location end, View3D view) { // TODO: Efficiency! float len = (float)(end - start).Length(); Location vecang = Utilities.VectorToAngles(start - end); vecang.Yaw += 180; Matrix4d mat = Matrix4d.Scale(len, 1, 1) * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(start.ToOpenTK3D()); view.SetMatrix(2, mat); GL.BindVertexArray(Line._VAO); GL.DrawElements(PrimitiveType.Lines, 2, DrawElementsType.UnsignedInt, IntPtr.Zero); }
/// <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 ProceduralParameters Build() { Vector2i detailLevel = new Vector2i( Math.Max(DetailLevel.X + 1, 3), Math.Max(DetailLevel.Y + 1, 3)); Vector2d inputSpan = MaxInput - MinInput; Matrix4d transform = Transform * Matrix4d.Scale(Size) * Matrix4d.Translate(Centre); // Write the vertices. int vo = Builder.VertexCount; for (int y = 0, i = 0; y < detailLevel.Y; y++) { for (int x = 0; x < detailLevel.X; x++, i++) { Vector2d input = (new Vector2d(x, y) * inputSpan + MinInput) / (Vector2d)(detailLevel - 1); Vector3d normal; Vector3d position = transform * SurfaceGenerator(ref input, out normal); Vector2d texel = TexelGenerator(ref input, ref position, ref normal); Builder.AddVertex(position); Builder.SetNormal(normal); Builder.SetTexel(texel); } } // Write the indices. for (int y = 0, i = 0; y < detailLevel.Y - 1; y++) { int s = vo + y * detailLevel.X, t = s + detailLevel.X; for (int x = 0; x < detailLevel.X - 1; x++, i += 6, s++, t++) { Builder.AddIndices( s, s + 1, t + 1, s, t + 1, t); } } Builder.FinishPart(Primitive.Triangles, Material ?? new ModelMaterial()); return(this); }
/// <summary> /// Renders a line box. /// </summary> public void RenderLineBox(Location min, Location max, Matrix4d?rot = null) { if (min.IsNaN() || min.IsInfinite() || max.IsNaN() || max.IsInfinite()) { SysConsole.Output(OutputType.WARNING, "Invalid line box from " + min + " to " + max); return; } GL.ActiveTexture(TextureUnit.Texture0); Engine.White.Bind(); View3D.CheckError("RenderLineBox: BindTexture"); Location halfsize = (max - min) / 2; if ((min + halfsize) == Location.Zero) { return; // ??? } if (Math.Abs(min.X + halfsize.X) < 1 || Math.Abs(min.Y + halfsize.Y) < 1 || Math.Abs(min.Z + halfsize.Z) < 1) { return; // ??? } if (Math.Abs(min.X) < 1 || Math.Abs(min.Y) < 1 || Math.Abs(min.Z) < 1) { return; // ??? } if (bbreak) { return; // TODO: Fix! } Matrix4d mat = Matrix4d.Scale(ClientUtilities.ConvertD(halfsize)) * (rot != null && rot.HasValue ? rot.Value : Matrix4d.Identity) * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(min + halfsize)); Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference! View3D.CheckError("RenderLineBox: SetMatrix"); GL.BindVertexArray(Box._VAO); View3D.CheckError("RenderLineBox: Bind VAO"); GL.DrawElements(PrimitiveType.Lines, 24, DrawElementsType.UnsignedInt, IntPtr.Zero); if (View3D.CheckError("RenderLineBox: Pass")) { SysConsole.Output(OutputType.DEBUG, "Caught: " + Box._VAO + ", " + min + ", " + max + ", " + halfsize); } }
public void RenderBillboard(Location pos, Location scale, Location facing) { // TODO: Quaternion magic? Location relang = Utilities.VectorToAngles(pos - facing); if (relang.IsInfinite() || relang.IsNaN()) { throw new Exception("Unable to handle billboard: relang=" + relang); } Matrix4d mat = Matrix4d.Scale(ClientUtilities.ConvertD(scale)) * Matrix4d.CreateTranslation(-0.5f, -0.5f, 0f) * Matrix4d.CreateRotationY((float)((relang.Y - 90) * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(relang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(pos)); Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference! GL.BindVertexArray(Square._VAO); GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero); GL.BindVertexArray(0); }
/// <summary> /// Render the entity as seen normally, in 3D. /// </summary> /// <param name="context">The render context.</param> public override void RenderStandard(RenderContext context) { foreach (EnableCap ec in DisabledCaps) { GL.Disable(ec); } if (DiffuseTexture != null) { GL.ActiveTexture(TextureUnit.Texture0); DiffuseTexture.Bind(); } context.Engine.Rendering.SetColor(Color, context.Engine.MainView); Matrix4d mat = Matrix4d.Scale(Scale.ToOpenTK3D()) * Matrix4d.CreateFromQuaternion(RenderOrientation.ToOpenTKDoubles()) * Matrix4d.CreateTranslation(RenderAt.ToOpenTK3D()); context.Engine.MainView.SetMatrix(ShaderLocations.Common.WORLD, mat); EntityModel.Draw(); foreach (EnableCap ec in DisabledCaps) { GL.Enable(ec); } }