public ShadowMap( VisionContent vContent, Camera camera, int width, int height, int nearPlane = 1, int farPlane = 200) { _graphicsDevice = vContent.GraphicsDevice; RealCamera = camera; ShadowDepthTarget = RenderTarget2D.New(_graphicsDevice, width, height, PixelFormat.R16G16.Float); _spriteBatch = new SpriteBatch(_graphicsDevice); _shadowBlurEffect = vContent.LoadPlainEffect("ShadowEffects/Blur"); _shadowBlurTarg = RenderTarget2D.New(_graphicsDevice, width, height, PixelFormat.R16G16.Float); ShadowNearPlane = nearPlane; ShadowFarPlane = farPlane; Camera = new Camera( new Vector2(width, height), Vector3.Zero, Vector3.Up, ShadowNearPlane, ShadowFarPlane); UpdateProjection(50, 50); }
public ShadowMap( VisionContent vContent, int width, int height, int nearPlane = 1, int farPlane = 200) { _graphicsDevice = vContent.GraphicsDevice; ShadowDepthTarget = RenderTarget2D.New(_graphicsDevice, width, height, PixelFormat.R16G16.Float); DepthStencilTarget = DepthStencilBuffer.New(_graphicsDevice, width, height, DepthFormat.Depth16); _spriteBatch = new SpriteBatch(_graphicsDevice); _shadowBlurEffect = vContent.LoadEffect("Effects/Blur"); _shadowBlurEffect.Parameters["dx"].SetValue(1f/width); _shadowBlurEffect.Parameters["dy"].SetValue(1f/height); _shadowBlurTarg = RenderTarget2D.New(_graphicsDevice, width, height, PixelFormat.R16G16.Float); ShadowNearPlane = nearPlane; ShadowFarPlane = farPlane; Camera = new Camera( new Vector2(width, height), Vector3.Zero, Vector3.Up, ShadowNearPlane, ShadowFarPlane); UpdateProjection(60, 60); }
public ShipModel(VisionContent vContent) : base(vContent.LoadEffect("effects/SimpleTextureEffect")) { _model = vContent.Load<Model>(@"Models/galleonmodel"); _texture = vContent.Load<Texture2D>(@"Models/galleon"); _boundingSphere = _model.CalculateBounds(); }
public Signs( VisionContent vContent, Matrix world, Texture2D texture, List<VisionClass> vclasses, float width, float height) : base(vContent, world, texture, width, height, 0) { _signTextEffect = vContent.LoadEffect("effects/signtexteffect"); _spriteBatch = new SpriteBatch(Effect.GraphicsDevice); _spriteFont = vContent.Load<SpriteFont>("fonts/BlackCastle"); _vclasses = vclasses; foreach (var vc in vclasses) { vc.GroundBoundingSphere = new BoundingSphere( vc.Position + world.TranslationVector, vc.R); vc.SignClickBoundingSphere = new BoundingSphere( vc.Position + world.TranslationVector + new Vector3(0, TextDistanceAboveGround - 2, 0), 2); } AddPositionsWithSameNormal(Vector3.Up, vclasses.Select(vc => vc.Position - world.TranslationVector).ToArray()); CreateVertices(false); }
public FloatingTexts(VisionContent vcontent, SpriteBatch spriteBatch, SpriteFont font) : base(vcontent.LoadEffect("effects/signtexteffect")) { VContent = vcontent; SpriteBatch = spriteBatch; Font = font; }
public SkySphere( VisionContent vtContent, Texture2DBase texture) : base(new VisionEffect(vtContent.Load<Effect>("effects/skysphere"))) { _sphere = new SpherePrimitive<VertexPosition>(vtContent.GraphicsDevice, (p, n, t, tx) => new VertexPosition(p), 20000, 10, false); Effect.Texture = texture; }
public ReimersBillboards( VisionContent vContent, Matrix world, GroundMap groundMap, ColorSurface normals, Texture2D texture) : base(vContent, world, texture, generateTreePositions(vContent.Load<Texture2D>("treeMap"), groundMap, normals), 6, 7) { }
public Bridge(VisionContent vContent, Matrix world) : base(vContent.LoadEffect("effects/SimpleTextureEffect")) { _model = vContent.Load<Model>(@"Models/bridge"); _texture = vContent.Load<Texture2D>("textures/bigstone"); World = world * Matrix.Scaling(0.05f); foreach (var part in _model.Meshes.SelectMany(mesh => mesh.MeshParts)) part.Effect = Effect.Effect; }
public DrawableBox(VisionContent vContent, Matrix world, Vector3 size, float texScale = 1) : base(vContent.LoadEffect("effects/SimpleTextureEffect")) { _texture = vContent.Load<Texture2D>("textures/brick_texture_map"); _bumpMap = vContent.Load<Texture2D>("textures/brick_normal_map"); _cube = new CubePrimitive<VertexPositionNormalTexture>( Effect.GraphicsDevice, (p,n,t) => createVertex(p,n,t,size,texScale), 1); World = world; }
public TerrainPlane(VisionContent vContent) { Effect = vContent.LoadPlainEffect("Effects/TerrainEffects"); _loPlane = new PlanePrimitive<TerrainVertex>( Effect.GraphicsDevice, (x, y, w, h) => new TerrainVertex( new Vector3(x, 0, y), new Vector2(x/SquareSize, y/SquareSize), x/SquareSize), SquareSize, SquareSize, 5); }
public CxBillboard( VisionContent vContent, Matrix world, Texture2D texture, float width, float height) : base(vContent.LoadPlainEffect("Billboards/CxBillboard", vContent.GraphicsDevice.SamplerStates.LinearClamp)) { _world = world; _texture = texture; _billboardWidth = width; _billboardHeight = height; }
public SimpleBillboards( VisionContent vContent, Matrix world, Texture2D texture, List<Vector3> positions, float width, float height) : base(vContent.LoadPlainEffect("Effects/BillboardEffect")) { World = world; _treeTexture = texture; Width = width; Height = height; Effect.Parameters["AllowedRotDir"].SetValue(Vector3.Up); createBillboardVerticesFromList(positions); }
public Windmill(VisionContent vContent, Vector3 location) : base(vContent.LoadEffect("effects/SimpleTextureEffect")) { World = Matrix.RotationY(-MathUtil.PiOverTwo)*Matrix.Scaling(0.005f)*Matrix.Translation(location); _model = vContent.Load<Model>("models/windmill"); _texture = vContent.Load<Texture2D>("textures/windmill_diffuse"); _bones = new Matrix[_model.Bones.Count]; _model.CopyAbsoluteBoneTransformsTo(_bones); //foreach (var mesh in _model.Meshes) // foreach (var part in mesh.MeshParts) // part.Effect = Effect.Effect; _animation = new ObjectAnimation(new Vector3(0, 875, 0), new Vector3(0, 875, 0), Vector3.Zero, new Vector3(0, 0, MathUtil.TwoPi), TimeSpan.FromSeconds(10), true); }
public Archipelag( VisionContent vContent, VProgram vprogram, WaterSurface water, ShadowMap shadow) : base((IVEffect)null) { var codeIslands = CodeIsland.Create(vContent, this, vprogram.VAssemblies); foreach (var codeIsland in codeIslands) { water.ReflectedObjects.Add(codeIsland); shadow.ShadowCastingObjects.Add(codeIsland); Children.Add(codeIsland); } _bannerSign = new BannerSign(vContent, codeIslands); _arcs = new Arcs(vContent, this); }
public BannerSign(VisionContent vContent, IEnumerable<CodeIsland> islands) : base(vContent.LoadEffect("effects/signtexteffect")) { _spriteBatch = new SpriteBatch(Effect.GraphicsDevice); _spriteFont = vContent.Load<SpriteFont>("fonts/BlackCastle"); _tpds = islands.Select(_ => new TextAndPosAndDistance { Text = _.VAssembly.Name, Pos = new Vector3(_.World.M41 + (float) _.GroundExtentX/2, HeightAboveOcean, _.World.M43 + (float) _.GroundExtentZ/2) }).ToList(); foreach (var tpd in _tpds) { var sz = _spriteFont.MeasureString(tpd.Text)/4*TextSize; var extent = new Vector3(sz.X, sz.Y, sz.X); tpd.BoundingBox = new BoundingBox(tpd.Pos - extent, tpd.Pos + extent); } }
public Arcs( VisionContent vContent, Archipelag archipelag) : base(vContent.LoadEffect("Effects/ArcsEffect")) { Archipelag = archipelag; Effect.World = Matrix.Identity; var lines = new List<ArcVertex>(); var modules = archipelag.CodeIslands.ToDictionary(ci => ci.VAssembly.Name, ci => ci); foreach (var island in modules.Values) processOneIsland(lines, island, island.VAssembly.VProgram, modules); if (lines.Any()) { _vertexBuffer = Buffer.Vertex.New(vContent.GraphicsDevice, lines.ToArray()); _vertexInputLayout = VertexInputLayout.FromBuffer(0, _vertexBuffer); } }
public static WaterSurface Create(VisionContent vContent) { return new WaterSurface( vContent.GraphicsDevice, new InitInfo { Fx = vContent.Load<Effect>("effects/reflectedwater"), LightDirection = VisionContent.SunlightDirectionReflectedWater, SquareSize = 128, dx = 0.25f, dz = 0.25f, dmap0 = foobar(vContent, "water/waterdmap0"), dmap1 = foobar(vContent, "water/waterdmap1"), waveMap0 = vContent.Load<Texture2D>("water/waterbump"), waveMap1 = vContent.Load<Texture2D>("water/wave1"), waveBumpMapVelocity0 = new Vector2(0.012f, 0.016f), waveBumpMapVelocity1 = new Vector2(0.014f, 0.018f), waveDispMapVelocity0 = new Vector2(0.012f, 0.015f), waveDispMapVelocity1 = new Vector2(0.014f, 0.05f), scaleHeights = new Vector2(0.7f, 1.1f), texScale = 8.0f }); }
protected override void LoadContent() { base.LoadContent(); _spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); _vContent = new VisionContent(_graphicsDeviceManager.GraphicsDevice, Content); _arial16Font = Content.Load<SpriteFont>("Fonts/Arial16"); _basicEffect = new VBasicEffect(_graphicsDeviceManager.GraphicsDevice); _basicEffect.EnableDefaultLighting(); _ball = new SpherePrimitive<VertexPositionNormalTexture>(GraphicsDevice, (p, n, t, tx) => new VertexPositionNormalTexture(p, n, tx), 1); var x = _vContent.LoadEffect("effects/simpletextureeffect"); x.Texture = _vContent.Load<Texture2D>("terraintextures/sand"); _ballInstance = new VDrawableInstance(x, _ball, Matrix.Translation(10, 2, 10)); Sky = new SkySphere(_vContent, _vContent.Load<TextureCube>(@"Textures\clouds")); _movingShip = new MovingShip(new ShipModel(_vContent)); _water = WaterFactory.Create(_vContent); _water.ReflectedObjects.Add(_movingShip._shipModel); _water.ReflectedObjects.Add(_ballInstance); _water.ReflectedObjects.Add(Sky); _camera = new Camera( _vContent.ClientSize, new KeyboardManager(this), new MouseManager(this), null, //new PointerManager(this), new Vector3(0, 15, 0), new Vector3(-10, 15, 0)); _rasterizerState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription { FillMode = FillMode.Solid, CullMode = CullMode.Back, IsFrontCounterClockwise = false, DepthBias = 0, SlopeScaledDepthBias = 0.0f, DepthBiasClamp = 0.0f, IsDepthClipEnabled = true, IsScissorEnabled = false, IsMultisampleEnabled = false, IsAntialiasedLineEnabled = false }); _shadow = new ShadowMap(_vContent, 1024, 1024); //_shadow.ShadowCastingObjects.Add(_sailingShip); //_shadow.ShadowCastingObjects.Add(reimersTerrain); //_shadow.ShadowCastingObjects.Add(generatedTerrain); //_shadow.ShadowCastingObjects.Add(bridge); //_archipelag = new Archipelag(_vContent, _water, _shadow); _data.VContent = _vContent; _data.Camera = _camera; _data.Water = _water; _data.Shadow = _shadow; _q = new CxBillboard(_vContent, Matrix.Identity, _vContent.Load<Texture2D>("billboards/wheat_billboard"), 20, 10, 0.5f); _q.AddPositionsWithSameNormal(Vector3.Up, Vector3.Zero, Vector3.Left*10.5f, Vector3.Up, Vector3.Right*10.4f, Vector3.Up, Vector3.ForwardRH*3.45f, Vector3.Up, Vector3.BackwardRH*2.9f, Vector3.Up); _q.CreateVertices(); }
private static Texture2D foobar(VisionContent vContent, string name) { using (var z = vContent.Load<Texture2D>(name)) { var oldData = new Color[z.Width*z.Height]; var newData = new float[z.Width*z.Height]; z.GetData(oldData); for (var i = 0; i < oldData.Length; i++) newData[i] = oldData[i].R/255f; var result = Texture2D.New(vContent.GraphicsDevice, z.Width, z.Height, PixelFormat.R32.Float); result.SetData(newData); return result; } }
private static TerrainPlane createTerrainPlaneSingleton(VisionContent vContent) { if (TerrainPlane == null) { TerrainPlane = new TerrainPlane(vContent); DrawableBox = new DrawableBox(vContent, Matrix.Identity, new Vector3(1, 50, 1)); } return TerrainPlane; }
public TerrainBase(VisionContent vContent) : base(vContent.TerrainPlane.Effect) { VContent = vContent; Effect.Parameters["Ambient"].SetValue(1.0f); }
protected override void LoadContent() { // Instantiate a SpriteBatch spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); // Loads a sprite font // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project //arial16Font = Content.Load<SpriteFont>("Arial16"); var lightVec = new Vector3(1, 0, 5); lightVec.Normalize(); // Creates a basic effect //basicEffect = ToDisposeContent(new VBasicEffect(GraphicsDevice)); var vContent = new VisionContent(GraphicsDevice, Content); //basicEffect = ToDisposeContent(new VBasicEffect(GraphicsDevice)); //_textureEffect = vContent.LoadPlainEffect("effects/simpletextureeffect"); _textureEffect = vContent.LoadPlainEffect("effects/simpletextureeffect"); _exampleEffect = vContent.LoadPlainEffect("exempeleffect"); _textureEffect.SunlightDirection = lightVec; _exampleEffect.SunlightDirection = lightVec; _textureEffect.Texture = Content.Load<Texture2D>("textures/brick_texture_map"); _exampleEffect.Texture = Content.Load<Texture2D>("textures/brick_texture_map"); //_textureEffect.Parameters["BumpMap"].SetResource(Content.Load<Texture2D>("textures/brick_normal_map")); _exampleEffect.Parameters["BumpMap"].SetResource(Content.Load<Texture2D>("textures/brick_normal_map")); //var be = (BasicEffect)basicEffect.Effect; //be.PreferPerPixelLighting = true; //be.EnableDefaultLighting(); //be.LightingEnabled = _lighting; // Creates torus primitive primitive = ToDisposeContent(new SpherePrimitive<VertexPositionNormalTangentTexture>(GraphicsDevice, (p, n, t, tx) => new VertexPositionNormalTangentTexture(p, n, t, tx), 2)); base.LoadContent(); }
public TerrainBase(VisionContent vContent) : base(createTerrainPlaneSingleton(vContent).Effect) { VContent = vContent; Effect.Parameters["Ambient"].SetValue(0.6f); }
public static List<CodeIsland> Create(VisionContent vContent, Archipelag archipelag, List<VAssembly> assemblies) { int x = 0, y = 0; return assemblies.OrderBy(_ => _.Is3DParty).Select(assembly => createOne(vContent, archipelag, assembly, ref x, ref y)).ToList(); }
public CodeIsland( VisionContent vContent, Archipelag archipelag, Matrix world, VAssembly vassembly) : base(vContent) { Archipelag = archipelag; VAssembly = vassembly; World = world; if (VAssembly.Is3DParty) { DrawableBox = new DrawableBox(vContent, World, new Vector3(50, 20, 50), 0.01f); foreach (var vclass in vassembly.VClasses) { var vc = new VisionClass(this, vclass, 75, 75, 5) {Height = 10}; Classes.Add(vclass.FullName, vc); } return; } var rnd = new Random(); var interfaceClasses = new List<VClass>(); var implementationClasses = new List<VClass>(); foreach (var vclass in vassembly.VClasses) if (vclass.IsInterface) interfaceClasses.Add(vclass); else implementationClasses.Add(vclass); var circleMaster = new CircleMaster<VClass>(); var q = 0; foreach (var vclass in interfaceClasses) circleMaster.Drop(q += 10, 0, 10, vclass); foreach (var vclass in implementationClasses) circleMaster.Drop(q += 5, 0, 4 + (int) Math.Sqrt(vclass.InstructionCount), vclass); int left, top, right, bottom; circleMaster.GetBounds(out left, out top, out right, out bottom); foreach (var c in circleMaster.Circles) { var vc = new VisionClass(this, c.Tag, ClassSide/2 + c.X - left, ClassSide/2 + c.Y - top, c.R); Classes.Add(c.Tag.FullName, vc); } var surfaceWidth = 1 << (1 + (int) (Math.Log(right - left)/Math.Log(2))); var surfaceHeight = 1 << (1 + (int) (Math.Log(bottom - top)/Math.Log(2))); System.Diagnostics.Debug.Print("{0}: {1} {2}", vassembly.Name, surfaceWidth, surfaceHeight); //var qq = Math.Max(surfaceWidth, surfaceHeight); var ground = new GroundMap(surfaceWidth, surfaceHeight); BoundingSphere = new BoundingSphere(new Vector3( world.TranslationVector.X + ground.Width / 2f, world.TranslationVector.Y, world.TranslationVector.Z + ground.Height / 2f), (float)Math.Sqrt(ground.Width * ground.Width + ground.Height * ground.Height) / 2); foreach (var vc in Classes.Values) { var instructHeight = (vc.VClass.IsInterface ? 40 : 10) + (float) Math.Pow(vc.VClass.InstructionCount, 0.3); var maintainabilityFactor = 3*(10 - vc.MaintainabilityIndex/10); var radius = vc.R; var middleX = vc.X - radius; var middleY = vc.Y - radius; var bellShapeFactor = 2f/(radius*1.7f); ground.AlterValues( middleX, middleY, radius*2, radius*2, (px, py, h) => { var dx = px - radius; var dy = py - radius; var d = (dx*dx + dy*dy)*bellShapeFactor*bellShapeFactor; var sharpness = (px & 1) != (py & 1) ? maintainabilityFactor : 0; return h + instructHeight*(float) Math.Exp(-d*d) + sharpness*(float) rnd.NextDouble(); }); var height = ground[vc.X, vc.Y]; vc.Height = height; } // raise the point where the sign is foreach (var vc in Classes.Values) ground[vc.X, vc.Y] += 6; //...and lower it... ground.Soften(2); //make GroundMap slices seamless for (var x = 64; x < surfaceWidth; x += TerrainPlane.SquareSize) for (var y = 0; y < surfaceHeight; y++) ground[x, y] = ground[x - 1, y] = (ground[x, y] + ground[x - 1, y])/2; for (var y = 64; y < surfaceHeight; y += TerrainPlane.SquareSize) for (var x = 0; x < surfaceWidth; x++) ground[x, y] = ground[x, y - 1] = (ground[x, y] + ground[x, y - 1])/2; foreach (var vc in Classes.Values) vc.Height = ground[vc.X, vc.Y]; var normals = ground.CreateNormalsMap(ref world); var signs = new Signs( vContent, world*Matrix.Translation(0, -0.1f, 0), vContent.Load<Texture2D>("billboards/woodensign"), Classes.Values.ToList(), 16, 4); Children.Add(signs); var qqq = world; //*Matrix.Translation(0, 0.05f, 0); var ms = new CxBillboard(vContent, Matrix.Identity, vContent.Load<Texture2D>("billboards/grass"), 1, 1, 0.5f); foreach (var vc in Classes.Values) { for (var i = (vc.CyclomaticComplexity - 1)*2; i > 0; i--) { var gx = vc.X + ((float) rnd.NextDouble() - 0.5f)*(ClassSide - 3); var gy = vc.Y + ((float) rnd.NextDouble() - 0.5f)*(ClassSide - 3); ms.Add( Vector3.TransformCoordinate(new Vector3(gx, ground.GetExactHeight(gx, gy), gy), qqq), normals.AsVector3(vc.X, vc.Y)); } } ms.CreateVertices(); Children.Add(ms); var weights = ground.CreateWeigthsMap(new[] {0, 0.40f, 0.60f, 0.9f}); //weights.DrawLine(0, 0, 20, 20, 1, (_, mt) => new Mt9Surface.Mt9 { I = 100 }); //weights.AlterValues(20, 20, 20, 20, (x, y, mt) => //{ // mt.B = 1; // return mt; //}); //weights.AlterValues(40, 40, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { C = 100 }); //weights.AlterValues(60, 60, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { D = 10 }); //weights.AlterValues(80, 80, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { E = 10 }); //weights.AlterValues(100, 100, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { F = 10 }); //weights.AlterValues(120, 120, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { G = 10 }); //weights.AlterValues(140, 140, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { H = 10 }); //weights.AlterValues(160, 160, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { I = 100, A = (float)Math.Sqrt(x * x + y * y) }); //foreach (var vc in Classes.Values.Where(_ => !_.CalledClasses.Any())) //{ // weights.AlterValues(vc.X - vc.R, vc.Y - vc.R, vc.R*2, vc.R*2, (x, y, mt) => new Mt9Surface.Mt9 {I = 100}); //} initialize(ground, weights, normals); }
private static CodeIsland createOne(VisionContent vContent, Archipelag archipelag, VAssembly assembly, ref int x, ref int y) { var t = Matrix.Translation(-y*600, -0.5f, -900 - x*600); var codeIsland = new CodeIsland(vContent, archipelag, t, assembly); x++; if (x > 4) { x = 0; y++; } return codeIsland; }