public int insert(string model, GraphicsDevice device, ContentManager Content, string cs_folder) { int rta = que_mesh(model); if (rta == -1) { meshes[rta = cant_meshes++] = new CSMDModel(model, device, Content, cs_folder); } return(rta); }
public weapon_reference(string weapon_name, GraphicsDevice p_device, ContentManager p_content, string p_folder, string ani_idle, string ani_reload, string ani_shoot) { model = new CSMDModel(weapon_name, p_device, p_content, p_folder); String ani_folder = weapon_name + "_anims"; model.cargar_ani(ani_folder, ani_idle); model.cargar_ani(ani_folder, ani_reload); model.cargar_ani(ani_folder, ani_shoot); model.anim[1].loop = false; model.setAnimation(0); }
public CEnemy(CBspFile p_scene, TGCGame p_game, CSMDModel p_model) : base(p_scene, p_game) { model = p_model; vel_lineal = model.speed; // 0 "ValveBiped.Bip01_Pelvis" -1 // 13 "ValveBiped.Bip01_Neck1" 12 // 14 "ValveBiped.Bip01_Head1" 13 // 45 "ValveBiped.weapon_bone" 9 int[] ndx_hp = { 0, 13, 14, 45 }; float[] hp_dw = { 10, 5, 5, 5 }; for (int i = 0; i < cant_hp; ++i) { hit_points[i] = new hit_point(); hit_points[i].Position = new Vector3(); hit_points[i].bone_id = ndx_hp[i]; hit_points[i].dw = hp_dw[i]; } }
void LoadContentGame() { font = Content.Load <SpriteFont>("SpriteFonts/Arial"); spriteBatch = new SpriteBatch(GraphicsDevice); EffectMesh = Content.Load <Effect>("Effects/BasicShader"); EffectSmd = Content.Load <Effect>("Effects/SMDEffect"); EffectSmd.CurrentTechnique = EffectSmd.Techniques["SkinnedMesh"]; // Arma weapon = new CWeapon(this, GraphicsDevice, Content, cs_folder); // Soldado soldier = new CSMDModel("player\\ct_sas", GraphicsDevice, Content, cs_folder); soldier.cargar_ani("player\\cs_player_shared_anims", "Death1"); soldier.anim[0].loop = false; soldier.cargar_ani("player\\cs_player_shared_anims", "a_WalkN"); soldier.anim[1].in_site = true; soldier_height = soldier.size.Y; soldier.debugEffect = EffectMesh; // Hostage for (int i = 0; i < NUM_HOSTAGE; ++i) { hostage_model[i] = new CSMDModel("characters\\hostage_0" + (i + 1).ToString(), GraphicsDevice, Content, cs_folder); hostage_model[i].cargar_ani("characters\\hostage_0" + (i + 1).ToString() + "_anims", "ragdoll"); hostage_model[i].anim[0].loop = false; hostage_model[i].debugEffect = EffectMesh; } // huevo de pascuas tgcLogo = Content.Load <Model>("Models/tgc-logo/tgc-logo"); var modelEffect = (BasicEffect)tgcLogo.Meshes[0].Effects[0]; modelEffect.DiffuseColor = Color.DarkBlue.ToVector3(); modelEffect.EnableDefaultLighting(); debug_box = new CDebugBox(GraphicsDevice); scene = new CBspFile(map_name, GraphicsDevice, Content); skybox = new CSkybox(GraphicsDevice); player = new CPlayer(scene, this); Random rnd = new Random(); for (int i = 0; i < MAX_ENEMIGOS; ++i) { enemigo[i] = new CEnemy(scene, this, soldier); enemigo[i].Position = new Vector3(rnd.Next((int)scene.p_min.X, (int)scene.p_max.X), scene.p_max.Y, rnd.Next((int)scene.p_min.Z, (int)scene.p_max.Z)); enemigo[i].Position = new Vector3(7242 + rnd.Next(-300, 300), -493, 6746 + rnd.Next(-300, 300)); float an = rnd.Next(0, 360) * MathF.PI / 180.0f; enemigo[i].Direction = new Vector3(MathF.Cos(an), 0, MathF.Sin(an)); enemigo[i].currentTime = rnd.Next(100); enemigo[i].currentAnimation = 1; } enemigo[0].PrevPosition = enemigo[0].Position = new Vector3(6447, -800, 6276); enemigo[0].Direction = new Vector3(0, 0, -1); player.Position = scene.info_player_start_pos; player.Direction = new Vector3(0, 0, 1); cant_hostages = scene.cant_hostages; for (int i = 0; i < cant_hostages; ++i) { hostage[i] = new CEnemy(scene, this, hostage_model[i % 4]); hostage[i].Position = scene.hostages[i].origin; hostage[i].Position.Y += hostage_model[i % 4].cg.Y; hostage[i].currentAnimation = 0; } base.LoadContent(); }
public void Draw(Matrix World, Matrix View, Matrix Proj) { device.SetVertexBuffer(VertexBuffer); Effect.CurrentTechnique = Effect.Techniques["Phong"]; Effect.Parameters["World"].SetValue(World); Effect.Parameters["View"].SetValue(View); Effect.Parameters["Projection"].SetValue(Proj); Effect.Parameters["Lightmap"].SetValue(lightmap); //device.BlendState = BlendState.AlphaBlend; device.BlendState = BlendState.Opaque; // escenario estatico var pos = 0; for (var i = 0; i < cant_subsets; i++) { var cant_tri = subset[i].cant_items; var cant_items = cant_tri * 3; if (cant_items > 0) { if (mostrar_tools || !subset[i].image_name.StartsWith("TOOLS")) //if (i == current_subset) { Effect.Parameters["ModelTexture"].SetValue(texture[i] != null ? texture[i] : texture_default); foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleList, pos, cant_tri); } } pos += cant_items; } } // modelos estaticos // primero layers opacos luego transparentes EffectMesh.CurrentTechnique = EffectMesh.Techniques["TextureDrawing"]; device.BlendState = BlendState.Opaque; for (var L = 0; L < 2; ++L) { for (var i = 0; i < cant_modelos; ++i) { Matrix world = modelos[i].world(); CSMDModel p_mesh = mesh_pool.meshes[modelos[i].nro_mesh]; p_mesh.Draw(device, EffectMesh, world, View, Proj, L); } // paso al layer transparente // activo el Blend y desactivo el zwrite device.BlendState = BlendState.AlphaBlend; // mejor lo activo, porque como no puedo dibujar en orden correcto, crea muchos artifacts //device.DepthStencilState = DepthStencilState.DepthRead; } //device.DepthStencilState = DepthStencilState.Default; // decals Effect.CurrentTechnique = Effect.Techniques["Phong"]; device.BlendState = BlendState.NonPremultiplied; device.DepthStencilState = DepthStencilState.DepthRead; device.SetVertexBuffer(decalsVertexBuffer); for (int i = 0; i < cant_decals; ++i) { if (!decals[i].blood) { Effect.Parameters["ModelTexture"].SetValue(decals[i].texture != null ? decals[i].texture : texture_default); foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleStrip, i * 4, 2); } } } // sangre Effect.CurrentTechnique = Effect.Techniques["Blood"]; for (int i = 0; i < cant_decals; ++i) { if (decals[i].blood) { Effect.Parameters["ModelTexture"].SetValue(decals[i].texture != null ? decals[i].texture : texture_default); foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleStrip, i * 4, 2); } } } device.DepthStencilState = DepthStencilState.Default; // debug bbb if (cant_debug_bb > 0) { device.SetVertexBuffer(bbVertexBuffer); Effect.CurrentTechnique = Effect.Techniques["DebugBB"]; foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleList, 0, cant_debug_bb / 3); } } // env sprites EffectMesh.CurrentTechnique = EffectMesh.Techniques["SpriteDrawing"]; var ant_blend_state = device.BlendState; device.BlendState = BlendState.Additive; var ant_z_state = device.DepthStencilState; var depthState = new DepthStencilState(); depthState.DepthBufferEnable = true; depthState.DepthBufferWriteEnable = false; device.DepthStencilState = depthState; EffectMesh.Parameters["View"].SetValue(Matrix.Identity); EffectMesh.Parameters["Projection"].SetValue(Proj); for (var i = 0; i < cant_sprites; ++i) { sprites[i].Draw(spriteVertexBuffer, EffectMesh, View); } device.BlendState = ant_blend_state; device.DepthStencilState = ant_z_state; }
public void DrawMap(CPlayer player, CEnemy [] enemigo) { Vector3 Position = player.Position; Vector3 Direction = player.Direction; Viewport ant_vp = device.Viewport; var vp = new Viewport(); vp.X = 10; vp.Y = 50; float aspect = (float)ant_vp.Width / (float)ant_vp.Height; vp.Width = vp.Height = 200; vp.MinDepth = 0; vp.MaxDepth = 1; device.Viewport = vp; device.RasterizerState = RasterizerState.CullNone; device.DepthStencilState = DepthStencilState.None; Effect.CurrentTechnique = Effect.Techniques["ClearScreen"]; Effect.Parameters["World"].SetValue(Matrix.Identity); Effect.Parameters["View"].SetValue(Matrix.Identity); Effect.Parameters["Projection"].SetValue(Matrix.Identity); device.SetVertexBuffer(spriteVertexBuffer); foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); } device.Clear(ClearOptions.DepthBuffer, Color.White, 1.0f, 0); Direction.Y = 0; Direction.Normalize(); Matrix View = Matrix.CreateLookAt(Position, Position + Direction * 100, new Vector3(0, 1, 0)); Matrix World = Matrix.Identity; float kx = 1.0f / size.X; float ky = 1.0f / size.Y; float kz = 1.0f / size.Z; kx *= 5 * aspect; kz *= 5; Matrix S = new Matrix(-kx, 0, 0, 0, 0, 0, ky, 0, 0, -kz, 0, 0, 0, 0, 0.5f, 1); Matrix Proj = S; device.SetVertexBuffer(VertexBuffer); Effect.CurrentTechnique = Effect.Techniques["Map"]; Effect.Parameters["World"].SetValue(World); Effect.Parameters["View"].SetValue(View); Effect.Parameters["Projection"].SetValue(Proj); Effect.Parameters["Lightmap"].SetValue(lightmap); device.BlendState = BlendState.AlphaBlend; // escenario estatico var pos = 0; for (var i = 0; i < cant_subsets; i++) { var cant_tri = subset[i].cant_items; var cant_items = cant_tri * 3; if (cant_items > 0) { if (mostrar_tools || !subset[i].image_name.StartsWith("TOOLS")) { Effect.Parameters["ModelTexture"].SetValue(texture[i] != null ? texture[i] : texture_default); foreach (var pass in Effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleList, pos, cant_tri); } } pos += cant_items; } } // modelos estaticos EffectMesh.CurrentTechnique = EffectMesh.Techniques["Map"]; for (var L = 0; L < 1; ++L) { for (var i = 0; i < cant_modelos; ++i) { Matrix world = modelos[i].world(); CSMDModel p_mesh = mesh_pool.meshes[modelos[i].nro_mesh]; p_mesh.Draw(device, EffectMesh, world, View, Proj, L); } } BeginDrawImage(); int W = device.Viewport.Width; int H = device.Viewport.Height; // dibujo la posicion del cero device.BlendState = BlendState.Additive; DrawImage(0, W / 2, H / 2, 20, 20); // dibujo la pos. de los enemigos Matrix T = World * View * Proj; for (int i = 0; i < enemigo.Length; ++i) { Vector4 v = Vector4.Transform(enemigo[i].Position, T); if (v.W > 0) { float x = v.X / v.W; float y = v.Y / v.W; float d = x * x + y * y; if (d < 0.9f) { int xs = (int)(W * (0.5f + x / 2)); int ys = (int)(H * (0.5 - y / 2)); DrawImage(2, xs - 5, ys - 5, 10, 10); } } } device.Viewport = ant_vp; device.DepthStencilState = DepthStencilState.Default; }