public override void OnRayPreview(Player _player, vec3 _worldPos, vec3 _worldNormal, bool _visible) { _worldPos = _player.AlignPlacementPosition(_worldPos); vec3 dx, dy, dz; _player.AlignmentSystem(_worldNormal, out dx, out dy, out dz); mat4 rotMat = new mat4(dx, dy, dz, vec3.Zero); // If the indicated volume is greater than the available volume, show limitation sphere. float volumeFactor = 0; float useVolume; switch (_player.CurrentDiggingShape) { case Player.DiggingShape.Box: volumeFactor = 8; break; case Player.DiggingShape.Cylinder: volumeFactor = 2 * (float)Math.PI; break; case Player.DiggingShape.Sphere: volumeFactor = 4f / 3f * (float)Math.PI; break; default: throw new InvalidOperationException("Unknown digging shape"); } useVolume = volumeFactor * useRadius * useRadius * useRadius; if (_visible && useVolume > Volume) { float availableRadius = (float)Math.Pow(Volume / volumeFactor, 1 / 3f); previewShapeLimited.ModelMatrix = mat4.Translate(_worldPos) * mat4.Scale(availableRadius) * rotMat; previewShapeLimited.SetColor("uMidPointAndRadius", new vec4(_worldPos, availableRadius)); } else { previewShapeLimited.ModelMatrix = mat4.Scale(0f); } // Radius of the primary preview is always use-radius. previewShape.ModelMatrix = _visible ? mat4.Translate(_worldPos) * mat4.Scale(useRadius) * rotMat : mat4.Scale(0f); previewShape.SetColor("uMidPointAndRadius", new vec4(_worldPos, useRadius)); previewShape.SetColor("uDigDirX", new vec4(dx, 0)); previewShape.SetColor("uDigDirY", new vec4(dy, 0)); previewShape.SetColor("uDigDirZ", new vec4(dz, 0)); previewShapeLimited.SetColor("uDigDirX", new vec4(dx, 0)); previewShapeLimited.SetColor("uDigDirY", new vec4(dy, 0)); previewShapeLimited.SetColor("uDigDirZ", new vec4(dz, 0)); // Indicator is always in the center and relatively small. previewShapeIndicator.ModelMatrix = _visible ? mat4.Translate(_worldPos) * mat4.Scale(.1f) * rotMat : mat4.Scale(0f); }
public override void OnRayPreview(Player _player, vec3 _worldPos, vec3 _worldNormal, bool _visible) { _worldPos = _player.AlignPlacementPosition(_worldPos); vec3 dx, dy, dz; _player.AlignmentSystem(_worldNormal, out dx, out dy, out dz); mat4 rotMat = new mat4(dx, dy, dz, vec3.Zero); // Limit shape if non-noclip if (!LocalScript.NoclipEnabled) { if (digRadiusShovel > digRadiusShovelInitial) { digRadiusShovel = digRadiusShovelInitial; } if (digRadiusShovel < digRadiusShovelInitial * digRadiusMinFactor) { digRadiusShovel = digRadiusShovelInitial * digRadiusMinFactor; } if (digRadiusPickaxe > digRadiusPickaxeInitial) { digRadiusPickaxe = digRadiusPickaxeInitial; } if (digRadiusPickaxe < digRadiusPickaxeInitial * digRadiusMinFactor) { digRadiusPickaxe = digRadiusPickaxeInitial * digRadiusMinFactor; } } float useRadius = 0.0f; switch (ToolType) { case ToolType.Pickaxe: useRadius = digRadiusPickaxe; break; case ToolType.Shovel: useRadius = digRadiusShovel; break; default: break; } // Set uniform for position and radius previewShape.SetColor("uMidPointAndRadius", new vec4(_worldPos, useRadius)); previewShape.SetColor("uDigDirX", new vec4(dx, 0)); previewShape.SetColor("uDigDirY", new vec4(dy, 0)); previewShape.SetColor("uDigDirZ", new vec4(dz, 0)); // Radius of the primary preview is always impact-radius of the current tool. previewShape.ModelMatrix = _visible ? mat4.Translate(_worldPos) * mat4.Scale(useRadius) * rotMat : mat4.Scale(0f); // Indicator is always in the center and relatively small. previewShapeIndicator.ModelMatrix = _visible ? mat4.Translate(_worldPos) * mat4.Scale(.1f) * rotMat : mat4.Scale(0f); }
public static Tree OldTree(Random random, mat4 transform1, mat4 transform2, World world) { bool type0 = random.NextDouble() > 0.5; MeshRenderJob leavesOpaque = new MeshRenderJob( Renderer.Opaque.Mesh, Resources.UseMaterial("TreeLeaves01", UpvoidMiner.ModDomain), Resources.UseMesh(type0 ? "Vegetation/Tree01/Leaves_high" : "Vegetation/Tree03/Leaves_high", UpvoidMiner.ModDomain), transform2); MeshRenderJob leavesZPre = new MeshRenderJob( Renderer.zPre.Mesh, Resources.UseMaterial("TreeLeaves01.zPre", UpvoidMiner.ModDomain), Resources.UseMesh(type0 ? "Vegetation/Tree01/Leaves_high" : "Vegetation/Tree03/Leaves_high", UpvoidMiner.ModDomain), transform2); MeshRenderJob leavesShadow = new MeshRenderJob( Renderer.Shadow.Mesh, Resources.UseMaterial("TreeLeaves01.Shadow", UpvoidMiner.ModDomain), Resources.UseMesh(type0 ? "Vegetation/Tree01/Leaves_high" : "Vegetation/Tree03/Leaves_high", UpvoidMiner.ModDomain), transform2); MeshRenderJob trunkOpaque = new MeshRenderJob( Renderer.Opaque.Mesh, Resources.UseMaterial("TreeTrunk", UpvoidMiner.ModDomain), Resources.UseMesh(type0 ? "Vegetation/Tree01/Trunk" : "Vegetation/Tree03/Trunk", UpvoidMiner.ModDomain), transform2); MeshRenderJob trunkShadow = new MeshRenderJob( Renderer.Shadow.Mesh, Resources.UseMaterial("::Shadow", UpvoidMiner.ModDomain), Resources.UseMesh(type0 ? "Vegetation/Tree01/Trunk" : "Vegetation/Tree03/Trunk", UpvoidMiner.ModDomain), transform2); // Add some color variance to trees vec4 colorModulation = new vec4(0.7f + (float)random.NextDouble() * 0.5f, 0.7f + (float)random.NextDouble() * 0.5f, 1, 1); leavesOpaque.SetColor("uColorModulation", colorModulation); // Amount of wood depends on tree type (thicker/thinner trunk) and tree height scale factor. Tree t = new Tree((type0 ? 0.5f : 1.0f) * transform2.col1.y, Tree.TreeType.Birch); Tree.Log l = new Tree.Log(); RigidBody b = new RigidBody(0f, transform1 * mat4.Translate(new vec3(0, 5, 0)), new CylinderShape(.5f, 10)); world.Physics.AddRigidBody(b); l.PhysicsComps.Add(new PhysicsComponent(b, mat4.Translate(new vec3(0, -5, 0)))); t.RjLeaves0.Add(new RenderComponent(leavesOpaque, transform2)); t.RjLeaves0.Add(new RenderComponent(leavesZPre, transform2)); t.RjLeaves0.Add(new RenderComponent(leavesShadow, transform2)); t.RjTrunk.Add(new RenderComponent(trunkOpaque, transform2)); t.RjTrunk.Add(new RenderComponent(trunkShadow, transform2)); t.Logs.Add(l); return(t); }
public static Tree Cactus(Random random, mat4 transform1, mat4 transform2, World world) { // Compute random cactus type \in 0..5 int type = (int)(random.NextDouble() * 6.0); // Circumvent the unlikely case of NextDouble() returning 1.0 if (type > 5) { type = 5; } // 0..5 -> 1..6 ++type; string meshString = "Vegetation/Cactus/Cactus" + type.ToString(); MeshRenderJob cactus = new MeshRenderJob( Renderer.Opaque.Mesh, Resources.UseMaterial("Cactus", UpvoidMiner.ModDomain), Resources.UseMesh(meshString, UpvoidMiner.ModDomain), transform2); MeshRenderJob cactusShadow = new MeshRenderJob( Renderer.Shadow.Mesh, Resources.UseMaterial("Cactus.Shadow", UpvoidMiner.ModDomain), Resources.UseMesh(meshString, UpvoidMiner.ModDomain), transform2); // Add some color variance to cacti vec4 colorModulation = new vec4(0.7f + (float)random.NextDouble() * 0.6f, 0.9f + (float)random.NextDouble() * 0.2f, 1, 1); cactus.SetColor("uColorModulation", colorModulation); // Create new Tree of type Cactus with 0 wood to gather. Tree t = new Tree(0, Tree.TreeType.Cactus); Tree.Log l = new Tree.Log(); RigidBody b = new RigidBody(0f, transform1 * mat4.Translate(new vec3(0, 5, 0)), new CylinderShape(.5f, 10)); world.Physics.AddRigidBody(b); l.PhysicsComps.Add(new PhysicsComponent(b, mat4.Translate(new vec3(0, -5, 0)))); t.RjLeaves0.Add(new RenderComponent(cactus, transform2)); t.RjLeaves0.Add(new RenderComponent(cactusShadow, transform2)); t.Logs.Add(l); return(t); }