public override void Init() { //Cargar 25 cajas formando una matriz var loader = new TgcSceneLoader(); boxes = new List <TgcBox>(); var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\granito.jpg"); var boxSize = new Vector3(30, 30, 30); for (var i = 0; i < 5; i++) { for (var j = 0; j < 5; j++) { var center = new Vector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, 0); var box = TgcBox.fromSize(center, boxSize, texture); boxes.Add(box); } } //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); Camara = new TgcRotationalCamera(new Vector3(100f, 100f, -250f), 600f); //FIXME esta camara deberi ser estatica y no rotacional, ya que sino trae problemas con el picking. //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TgcBox.fromSize(new Vector3(3, 3, 3), Color.Red); selected = false; //UserVars para mostrar en que punto hubo colision UserVars.addVar("CollP-X:"); UserVars.addVar("CollP-Y:"); UserVars.addVar("CollP-Z:"); }
/// <summary> /// Detectar el eje seleccionado /// </summary> public void detectSelectedAxis(TgcPickingRay pickingRay) { pickingRay.updateRay(); TGCVector3 collP; //Buscar colision con eje con Picking if (TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, boxX.BoundingBox, out collP)) { SelectedAxis = Axis.X; selectedAxisBox = boxX; } else if (TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, boxY.BoundingBox, out collP)) { SelectedAxis = Axis.Y; selectedAxisBox = boxY; } else if (TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, boxZ.BoundingBox, out collP)) { SelectedAxis = Axis.Z; selectedAxisBox = boxZ; } else { SelectedAxis = Axis.None; selectedAxisBox = null; } //Desplazamiento inicial if (SelectedAxis != Axis.None) { initMouseP = new TGCVector2(input.XposRelative, input.YposRelative); } }
public override void Init() { //Cargar 25 cajas formando una matriz var loader = new TgcSceneLoader(); boxes = new List <TGCBox>(); var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\granito.jpg"); var boxSize = new TGCVector3(30, 30, 30); for (var i = 0; i < 5; i++) { for (var j = 0; j < 5; j++) { var center = new TGCVector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, 0); var box = TGCBox.fromSize(center, boxSize, texture); box.Transform = TGCMatrix.Translation(box.Position); boxes.Add(box); } } //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(Input); Camara.SetCamera(new TGCVector3(100f, 100f, -500f), new TGCVector3(100f, 100f, -250f)); //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TGCBox.fromSize(new TGCVector3(3, 3, 3), Color.Red); selected = false; //UserVars para mostrar en que punto hubo colision UserVars.addVar("CollP-X:"); UserVars.addVar("CollP-Y:"); UserVars.addVar("CollP-Z:"); }
public FPSCamara(TgcCamera Camara, TgcD3dInput Input) { this.Camara = Camara; this.Input = Input; this.ray = new TgcPickingRay(Input); }
public void Init(TgcD3dInput Input) { crearTableroPicking(5, 9); pickingRay = new TgcPickingRay(Input); //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TGCBox.fromSize(new TGCVector3(3, 3, 3), Color.Red); collisionPointMesh.AutoTransform = true; selected = false; #region configurarEfecto efecto = TgcShaders.loadEffect(GameModel.shadersDir + "shaderPlanta.fx"); #endregion #region contenedor contenedor = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\contenedor-TgcScene.xml").Meshes[0]; contenedor.Scale = new TGCVector3(45.5f, 45.5f, 45.5f); contenedor.Position = new TGCVector3(-2000f, 400f, -800f); contenedor.Effect = efecto; contenedor.Technique = "RenderSceneProgresivo"; objetos.Add(contenedor); //glowObjects.Add(contenedor); #endregion //este body seria del tablero o isla principal body = FactoryBody.crearBodyIsla(); callback = new CollisionCallbackIsla(logica); logica.addBulletObject(this); PostProcess.agregarPostProcessObject(this); }
public void Init(TgcD3dInput Input) { crearItems(); pickingRay = new TgcPickingRay(Input); //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TGCBox.fromSize(new TGCVector3(3, 3, 3), Color.Red); collisionPointMesh.AutoTransform = true; selected = false; }
/// <summary> /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. /// Escribir aquí todo el código de inicialización: cargar modelos, texturas, estructuras de optimización, todo /// procesamiento que podemos pre calcular para nuestro juego. /// Borrar el codigo ejemplo no utilizado. /// </summary> public override void Init() { //Device de DirectX para crear primitivas. d3dDevice = D3DDevice.Instance.Device; //Instancio el loader del framework loader = new TgcSceneLoader(); //creo usuario Player1 = new Player(); Player1.gameModel = this; //inicializo mesh para hacha Axe = loader.loadSceneFromFile(MediaDir + "Meshes\\Hacha\\Hacha-TgcScene.xml").Meshes[0]; //Inicializo cámara MyCamera = new TgcFpsCamera(Player1, Axe, Input, (MapLength / 2), -(MapLength / 2), (MapLength / 2), -(MapLength / 2)); Camara = MyCamera; Frustum.updateVolume(D3DDevice.Instance.Device.Transform.View, D3DDevice.Instance.Device.Transform.Projection); //genero el mundo MyWorld = new World(MediaDir, d3dDevice, loader, Camara, Frustum, MapLength, true); MyWorld.RenderDistance = RenderDistance; //inicializo efectos effectsManager = new EffectsManager(ShadersDir, this, MyWorld, ElapsedTime); effectsManager.applyEffect(Axe); //emisor de partículas emitter = new ParticleEmitter(MediaDir + "Textures\\smokeParticle.png", 10); emitter.Position = new Vector3(0, 0, 0); emitter.MinSizeParticle = 2f; emitter.MaxSizeParticle = 5f; emitter.ParticleTimeToLive = 1f; emitter.CreationFrecuency = 1f; emitter.Dispersion = 25; emitter.Speed = new Vector3(5f, 5f, 5f); //colisiones pickingRay = new TgcPickingRay(Input); //sonidos soundPlayer = new SoundPlayer(DirectSound, MediaDir); soundPlayer.startAmbient(); //gui MenuInterface = new GUI(MediaDir, D3DDevice.Instance, Player1, this); TopRightText = GameUtils.createText("", 0, 0, 20, true); TopRightText.Color = Color.LightGray; TopRightText.Align = TgcText2D.TextAlign.RIGHT; CenterText = GameUtils.createText("", 0, (D3DDevice.Instance.Height * 0.85f), 25, true); CenterText.Color = Color.DodgerBlue; CenterText.Align = TgcText2D.TextAlign.CENTER; }
public SceneEditorControl(TgcSceneEditor editor) { InitializeComponent(); this.editor = editor; parser = new TgcSceneParser(); sceneLoader = new TgcSceneLoader(); pickingRay = new TgcPickingRay(); translateGizmo = new SceneEditorTranslateGizmo(); helpWindow = new SceneEditorHelpWindow(); //openMeshDialog openMeshDialog = new OpenFileDialog(); openMeshDialog.CheckFileExists = true; openMeshDialog.Title = "Seleccionar malla de formato TGC"; openMeshDialog.Filter = "-TgcScene.xml |*-TgcScene.xml"; openMeshDialog.Multiselect = false; //openMeshDialog.InitialDirectory = GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\"; openMeshDialog.FileName = GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Box\\Box-TgcScene.xml"; fileName.Text = "Box-TgcScene.xml"; meshFilePath = openMeshDialog.FileName; //openHeighmapDialog openHeighmapDialog = new OpenFileDialog(); openHeighmapDialog.CheckFileExists = true; openHeighmapDialog.Title = "Seleccionar Heighmap"; openHeighmapDialog.Filter = ".JPG|*.jpg|.JPEG|*.jpeg|.GIF|*.gif|.PNG|*.png|.BMP|*.bmp | .TGA |*.tga"; openHeighmapDialog.Multiselect = false; openHeighmapDialog.InitialDirectory = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\"; //openHeighmapDialog openTextureDialog = new OpenFileDialog(); openTextureDialog.CheckFileExists = true; openTextureDialog.Title = "Seleccionar textura de terreno"; openTextureDialog.Filter = ".JPG|*.jpg|.JPEG|*.jpeg|.GIF|*.gif|.PNG|*.png|.BMP|*.bmp | .TGA |*.tga"; openTextureDialog.Multiselect = false; openTextureDialog.InitialDirectory = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\"; //saveSceneDialog saveSceneDialog = new SaveFileDialog(); saveSceneDialog.DefaultExt = ".xml"; saveSceneDialog.Filter = ".XML |*.xml"; saveSceneDialog.AddExtension = true; selectedMeshList = new List <SceneEditorMeshObject>(); //Estado inicial currentState = GuiState.Nothing; tabControl.SelectedTab = tabControl.TabPages["tabPageCreate"]; //Camara inicial GuiController.Instance.FpsCamera.setCamera(new Vector3(50.406f, 185.5353f, -143.7283f), new Vector3(-92.5515f, -567.6361f, 498.3744f)); }
public bool DetectarClick(TgcPickingRay pickingRay) { pickingRay.updateRay(); var output = TGCVector3.One; if (TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, mesh.BoundingBox, out output)) { return(true); } return(false); }
public override void Render() { PreRender(); var size = (Vector2)Modifiers.getValue("size"); var position = (Vector3)Modifiers.getValue("position"); var rotation = (Vector3)Modifiers.getValue("rotation"); collider.Center = position; collider.Rotation = rotation; collider.Radius = size.X; collider.Length = size.Y; collider.updateValues(); if (TgcCollisionUtils.testSphereCylinder(collisionableSphere, collider)) { collisionableSphere.setRenderColor(collisionColor); } else { collisionableSphere.setRenderColor(noCollisionColor); } if (pickingTimeLeft > 0) { pickingTimeLeft -= ElapsedTime; } else { collider.setRenderColor(noCollisionColor); } if (TgcD3dInput.Instance.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT)) { var pickingRay = new TgcPickingRay(); pickingRay.updateRay(); if (TgcCollisionUtils.testRayCylinder(pickingRay.Ray, collider)) { pickingTimeLeft = PICKING_TIME; collider.setRenderColor(pickingColor); } } collider.render(); collisionableSphere.render(); PostRender(); }
public override void Init() { stacked = TGCQuaternion.Identity; fromDrag = TGCVector3.Empty; dragging = false; currentPick = TGCVector3.Empty; InitializeSphere(); InitializeShark(); InitializeArrows(); pickingRay = new TgcPickingRay(Input); Camera.SetCamera(new TGCVector3(20f, 0f, 20f), new TGCVector3(-1f, 0f, -1f)); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Cargar suelo TgcTexture texture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\granito.jpg"); suelo = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(5000, 0.1f, 5000), texture); //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); //Cargar nave TgcSceneLoader loader = new TgcSceneLoader(); TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\NaveEspacial\\NaveEspacial-TgcScene.xml"); mesh = scene.Meshes[0]; //Rotación original de la malla, hacia -Z originalMeshRot = new Vector3(0, 0, -1); //Manipulamos los movimientos del mesh a mano mesh.AutoTransformEnable = false; meshRotationMatrix = Matrix.Identity; newPosition = mesh.Position; applyMovement = false; //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TgcBox.fromSize(new Vector3(3, 100, 3), Color.Red); //Flecha para marcar la dirección directionArrow = new TgcArrow(); directionArrow.Thickness = 5; directionArrow.HeadSize = new Vector2(10, 10); //Camara en tercera persona GuiController.Instance.ThirdPersonCamera.Enable = true; GuiController.Instance.ThirdPersonCamera.setCamera(mesh.Position, 800, 1500); GuiController.Instance.Modifiers.addFloat("speed", 1000, 5000, 2500); }
public override void render(float elapsedTime) { TgcModifiers modifiers = GuiController.Instance.Modifiers; Vector2 size = (Vector2)modifiers.getValue("size"); Vector3 position = (Vector3)modifiers.getValue("position"); Vector3 rotation = (Vector3)modifiers.getValue("rotation"); collider.Center = position; collider.Rotation = rotation; collider.Radius = size.X; collider.Length = size.Y; collider.updateValues(); if (TgcCollisionUtils.testSphereCylinder(collisionableSphere, collider)) { collisionableSphere.setRenderColor(collisionColor); } else { collisionableSphere.setRenderColor(noCollisionColor); } if (pickingTimeLeft > 0) { pickingTimeLeft -= elapsedTime; } else { collider.setRenderColor(noCollisionColor); } if (GuiController.Instance.D3dInput.buttonPressed(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_LEFT)) { TgcPickingRay pickingRay = new TgcPickingRay(); pickingRay.updateRay(); if (TgcCollisionUtils.testRayCylinder(pickingRay.Ray, collider)) { pickingTimeLeft = PICKING_TIME; collider.setRenderColor(pickingColor); } } collider.render(); collisionableSphere.render(); }
private TgcMesh pickVegetation(TgcTerrainEditor editor) { TgcPickingRay ray = new TgcPickingRay(); ray.updateRay(); float minT = -1; TgcMesh closerMesh = null; foreach (TgcMesh v in editor.Vegetation) { Vector3 q; if (TgcCollisionUtils.intersectRayAABB(ray.Ray, v.BoundingBox, out q)) { float t = 0; if (q != ray.Ray.Origin) { if (ray.Ray.Direction.X != 0) { t = (q.X - ray.Ray.Origin.X) / ray.Ray.Direction.X; } else if (ray.Ray.Direction.Y != 0) { t = (q.Y - ray.Ray.Origin.Y) / ray.Ray.Direction.Y; } else if (ray.Ray.Direction.Z != 0) { t = (q.Z - ray.Ray.Origin.Z) / ray.Ray.Direction.Z; } } if (minT == -1 || t < minT) { minT = t; closerMesh = v; } } } if (closerMesh != null) { editor.removeVegetation(closerMesh); } return(closerMesh); }
public override void Init(GameModel _env) { base.Init(_env); Reset(); hasGanado.Text = "¡Felicitaciones, has ganado!"; hasGanado.Align = TgcText2D.TextAlign.CENTER; hasGanado.changeFont(new System.Drawing.Font("Comic Sans MS", 50, FontStyle.Bold)); hasGanado.Position = new Point(D3DDevice.Instance.Width / 2 - 700, D3DDevice.Instance.Height / 2 - 200); hasGanado.Color = Color.Green; buttons.Add(new QuadButton(pos, 0, 15, "Menú Principal", () => { Env.CambiarEscenario("Menu"); }, Color.DarkCyan)); pickingRay = new TgcPickingRay(Env.Input); useShadows = false; }
public override void Init() { //Crear suelo var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\Quake\\quakeWall3.jpg"); suelo = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(500, 0.1f, 500), texture); //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); //Cargar modelos que se pueden seleccionar modelos = new List <TgcMesh>(); modelosSeleccionados = new List <TgcMesh>(); //Modelo 1, original var loader = new TgcSceneLoader(); var scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Carretilla\\Carretilla-TgcScene.xml"); var modeloOrignal = scene.Meshes[0]; modelos.Add(modeloOrignal); //Modelos instancias del original modelos.Add(modeloOrignal.createMeshInstance("Carretilla2", new Vector3(100, 0, 0), Vector3.Empty, new Vector3(1, 1, 1))); modelos.Add(modeloOrignal.createMeshInstance("Carretilla3", new Vector3(50, 0, -70), Vector3.Empty, new Vector3(1, 1, 1))); modelos.Add(modeloOrignal.createMeshInstance("Carretilla4", new Vector3(-100, 0, -30), Vector3.Empty, new Vector3(1, 1, 1))); modelos.Add(modeloOrignal.createMeshInstance("Carretilla5", new Vector3(-70, 0, -80), Vector3.Empty, new Vector3(1, 1, 1))); //Crear caja para marcar en que lugar hubo colision selectionBox = TgcBox.fromSize(new Vector3(3, SELECTION_BOX_HEIGHT, 3), Color.Red); selectionBox.BoundingBox.setRenderColor(Color.Red); selecting = false; Camara = new TgcRotationalCamera(new Vector3(0f, 100f, 0f), 300f); //FIXME esta camara deberi ser estatica y no rotacional, ya que sino trae problemas con el picking. }
public override void Init() { //-------ESCENA--------// var loader = new TgcSceneLoader(); //clase para cargar el terreno var center = TGCVector3.Empty; //posicion inicial para la scene scene = loader.loadSceneFromFile(MediaDir + "Selva\\Selva-TgcScene.xml"); var pathTextura = MediaDir + "Walls.jpg"; pista = new Track(center, pathTextura, 5); //------SKYBOX------// skyBox = new TgcSkyBox(); skyBox.Center = TGCVector3.Empty; skyBox.Size = new TGCVector3(10000, 10000, 10000); var pathSkybox = MediaDir + "SkyBox\\"; skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, pathSkybox + "Back.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, pathSkybox + "Front.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, pathSkybox + "Left.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, pathSkybox + "Right.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, pathSkybox + "Up.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, pathSkybox + "Down.jpg"); skyBox.Init(); this.ship = new Player(loader, MediaDir, ShadersDir, Input); //------ENEMIGO------// enemigo = new Enemy(MediaDir + "Enemy\\", new TGCVector3(0, 0, 200)); pickingRay = new TgcPickingRay(Input); //-------CAMARA--------// camera = new CamaraNave(ship.Position, 0); Camara = camera; buliEne = true; }
public override void Init() { //Cargar suelo var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\granito.jpg"); suelo = new TgcPlane(new TGCVector3(-5000, 0, -5000), new TGCVector3(10000, 0f, 10000), TgcPlane.Orientations.XZplane, texture); //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(Input); //Cargar nave var loader = new TgcSceneLoader(); var scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\NaveEspacial\\NaveEspacial-TgcScene.xml"); mesh = scene.Meshes[0]; //Rotación original de la malla, hacia -Z originalMeshRot = new TGCVector3(0, 0, -1); //Manipulamos los movimientos del mesh a mano mesh.AutoTransform = false; meshRotationMatrix = TGCMatrix.Identity; newPosition = mesh.Position; applyMovement = false; //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TGCBox.fromSize(new TGCVector3(3, 100, 3), Color.Red); //Flecha para marcar la dirección directionArrow = new TgcArrow(); directionArrow.Thickness = 5; directionArrow.HeadSize = new TGCVector2(10, 10); //Camara en tercera persona camaraInterna = new TgcThirdPersonCamera(mesh.Position, 800, 1500); Camara = camaraInterna; speedModifier = AddFloat("speed", 1000, 5000, 2500); }
public override void Init() { //Crear suelo var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\Quake\\quakeWall3.jpg"); suelo = new TgcPlane(new TGCVector3(-500, 0, -500), new TGCVector3(1000, 0f, 1000), TgcPlane.Orientations.XZplane, texture); //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(Input); //Cargar modelos que se pueden seleccionar modelos = new List <TgcMesh>(); modelosSeleccionados = new List <TgcMesh>(); //Modelo 1, original var loader = new TgcSceneLoader(); var scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Carretilla\\Carretilla-TgcScene.xml"); var modeloOrignal = scene.Meshes[0]; modelos.Add(modeloOrignal); //Modelos instancias del original modelos.Add(modeloOrignal.createMeshInstance("Carretilla2", new TGCVector3(100, 0, 0), TGCVector3.Empty, TGCVector3.One)); modelos.Add(modeloOrignal.createMeshInstance("Carretilla3", new TGCVector3(50, 0, -70), TGCVector3.Empty, TGCVector3.One)); modelos.Add(modeloOrignal.createMeshInstance("Carretilla4", new TGCVector3(-100, 0, -30), TGCVector3.Empty, TGCVector3.One)); modelos.Add(modeloOrignal.createMeshInstance("Carretilla5", new TGCVector3(-70, 0, -80), TGCVector3.Empty, TGCVector3.One)); //Crear caja para marcar en que lugar hubo colision selectionBox = TGCBox.fromSize(new TGCVector3(3, SELECTION_BOX_HEIGHT, 3), Color.Red); selectionBox.BoundingBox.setRenderColor(Color.Red); selecting = false; Camara.SetCamera(new TGCVector3(250f, 250f, 250f), new TGCVector3(0f, 0f, 0f)); }
public override void Init(GameModel _env) { base.Init(_env); Reset(); hasMuerto.Text = "Has muerto, vuelve a intentarlo"; hasMuerto.Align = TgcText2D.TextAlign.CENTER; hasMuerto.changeFont(new System.Drawing.Font("Comic Sans MS", 50, FontStyle.Bold)); hasMuerto.Position = new Point(D3DDevice.Instance.Width / 2 - 700, D3DDevice.Instance.Height / 2 - 200); hasMuerto.Color = Color.DarkRed; buttons.Add(new QuadButton(pos, 0, 10, "Reiniciar", () => { Env.Personaje.Reset(); Env.CambiarEscenario("Escenario1"); }, Color.DarkCyan)); buttons.Add(new QuadButton(pos, 0, 15, "Menú Principal", () => { Env.CambiarEscenario("Menu"); }, Color.DarkCyan)); pickingRay = new TgcPickingRay(Env.Input); useShadows = false; }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Cargar 25 cajas formando una matriz TgcSceneLoader loader = new TgcSceneLoader(); boxes = new List <TgcBox>(); TgcTexture texture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\granito.jpg"); Vector3 boxSize = new Vector3(30, 30, 30); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { Vector3 center = new Vector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, 0); TgcBox box = TgcBox.fromSize(center, boxSize, texture); boxes.Add(box); } } //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); //Camara fija GuiController.Instance.RotCamera.Enable = false; GuiController.Instance.setCamera(new Vector3(94.9854f, 138.4992f, -284.3344f), new Vector3(86.4563f, -15.4191f, 703.7123f)); //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TgcBox.fromSize(new Vector3(3, 3, 3), Color.Red); selected = false; //UserVars para mostrar en que punto hubo colision GuiController.Instance.UserVars.addVar("CollP-X:"); GuiController.Instance.UserVars.addVar("CollP-Y:"); GuiController.Instance.UserVars.addVar("CollP-Z:"); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Crear suelo TgcTexture texture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\quakeWall3.jpg"); suelo = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(500, 0.1f, 500), texture); //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); //Cargar modelos que se pueden seleccionar modelos = new List <TgcMesh>(); modelosSeleccionados = new List <TgcMesh>(); //Modelo 1, original TgcSceneLoader loader = new TgcSceneLoader(); TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\Carretilla\\Carretilla-TgcScene.xml"); TgcMesh modeloOrignal = scene.Meshes[0]; modelos.Add(modeloOrignal); //Modelos instancias del original modelos.Add(modeloOrignal.createMeshInstance("Carretilla2", new Vector3(100, 0, 0), Vector3.Empty, new Vector3(1, 1, 1))); modelos.Add(modeloOrignal.createMeshInstance("Carretilla3", new Vector3(50, 0, -70), Vector3.Empty, new Vector3(1, 1, 1))); modelos.Add(modeloOrignal.createMeshInstance("Carretilla4", new Vector3(-100, 0, -30), Vector3.Empty, new Vector3(1, 1, 1))); modelos.Add(modeloOrignal.createMeshInstance("Carretilla5", new Vector3(-70, 0, -80), Vector3.Empty, new Vector3(1, 1, 1))); //Crear caja para marcar en que lugar hubo colision selectionBox = TgcBox.fromSize(new Vector3(3, SELECTION_BOX_HEIGHT, 3), Color.Red); selectionBox.BoundingBox.setRenderColor(Color.Red); selecting = false; //Camara fija GuiController.Instance.RotCamera.Enable = false; GuiController.Instance.setCamera(new Vector3(-4.4715f, 239.1167f, 179.248f), new Vector3(-4.4742f, 238.3456f, 178.6113f)); }
public override void Init(GameModel _env) { base.Init(_env); Reset(); buttons.Add(new QuadButton(pos, 0, -10, "Nueva Partida", () => { Env.Personaje.Reset(); Env.CambiarEscenario("Escenario1"); // Env.CambiarEscenario(0); }, Color.DarkCyan)); /*buttons.Add(new SpriteButton(pos, 0, -15, Env.MediaDir + "\\Menu\\BotonIniciarPartida.jpg", () => { * Env.Personaje.Reset(); * Env.CambiarEscenario(0); * })); */ buttons.Add(new QuadButton(pos, 0, -5, "Continuar", () => { Env.Personaje.yaJugo = true; Env.CambiarEscenario("Escenario1"); }, Color.DarkCyan)); /*buttons.Add(new SpriteButton(pos, 0, -15, Env.MediaDir + "\\Menu\\Continuar.jpg", () => { * Env.CambiarEscenario(0); * }));*/ buttons.Add(new QuadButton(pos, 0, 0, "Cargar Partida", () => { Env.LoadPartida(); Env.CambiarEscenario("Escenario1"); }, Color.DarkCyan)); buttons.Add(new QuadButton(pos, 0, 5, "Guardar Partida", () => { Env.guardarPartida(); }, Color.DarkCyan)); buttons.Add(new QuadButton(pos, 0, 10, "Modo Bullet", () => { Env.Personaje.Reset(); Env.CambiarEscenario("Bullet1"); }, Color.DarkCyan)); buttons.Add(new QuadButton(pos, 0, 15, "Exit", () => { Environment.Exit(0); }, Color.DarkCyan)); pickingRay = new TgcPickingRay(Env.Input); useShadows = false; }
public override void Init() { //Configurar FPS Camara TerrainFpsCamera = new TerrainFpsCamera(Input); Camera = TerrainFpsCamera; Camera.RotateMouseButton = cameraRotationButton; Camera.setCamera(new TGCVector3(-722.6171f, 495.0046f, -31.2611f), new TGCVector3(164.9481f, 35.3185f, -61.5394f)); this.Camera = Camera; Terrain = new SmartTerrain(); brush = new DummyBrush(); Vegetation = new List <TgcMesh>(); pickingRay = new TgcPickingRay(Input); ShowVegetation = true; mouseMove = Panel3d_MouseMove; mouseLeave = Panel3d_MouseLeave; noBrush = new DummyBrush(); ToolsModel.Instance.Panel3d.MouseMove += mouseMove; ToolsModel.Instance.Panel3d.MouseLeave += mouseLeave; labelFPS = new TgcText2D(); labelFPS.Text = "Press F to go back to edition mode"; labelFPS.changeFont(new Font("Arial", 12, FontStyle.Bold)); labelFPS.Color = Color.Red; labelFPS.Align = TgcText2D.TextAlign.RIGHT; labelVegetationHidden = new TgcText2D(); labelVegetationHidden.Text = "Press V to show vegetation"; labelVegetationHidden.changeFont(new Font("Arial", 12, FontStyle.Bold)); labelVegetationHidden.Color = Color.GreenYellow; labelVegetationHidden.Format = DrawTextFormat.Bottom | DrawTextFormat.Center; //Crear Modifier especial para este editor Modifier = AddTerrainEditorModifier(this); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; camera = new TerrainFpsCamera(); Terrain = new SmartTerrain(); this.brush = new DummyBrush(); this.vegetation = new List <TgcMesh>(); modifierPanel = new TerrainEditorModifier("Panel", this); GuiController.Instance.Modifiers.add(modifierPanel); pickingRay = new TgcPickingRay(); ShowVegetation = true; mouseMove = new MouseEventHandler(Panel3d_MouseMove); mouseLeave = new EventHandler(Panel3d_MouseLeave); noBrush = new DummyBrush(); GuiController.Instance.Panel3d.MouseMove += mouseMove; GuiController.Instance.Panel3d.MouseLeave += mouseLeave; //Configurar FPS Camara camera.Enable = true; camera.RotateMouseButton = cameraRotationButton; camera.setCamera(new Vector3(-722.6171f, 495.0046f, -31.2611f), new Vector3(164.9481f, 35.3185f, -61.5394f)); labelFPS = new TgcText2d(); labelFPS.Text = "Press F to go back to edition mode"; labelFPS.changeFont(new System.Drawing.Font("Arial", 12, FontStyle.Bold)); labelFPS.Color = Color.Red; labelFPS.Align = TgcText2d.TextAlign.RIGHT; labelVegetationHidden = new TgcText2d(); labelVegetationHidden.Text = "Press V to show vegetation"; labelVegetationHidden.changeFont(new System.Drawing.Font("Arial", 12, FontStyle.Bold)); labelVegetationHidden.Color = Color.GreenYellow; labelVegetationHidden.Format = DrawTextFormat.Bottom | DrawTextFormat.Center; }
protected override void Init() { pickingRay = new TgcPickingRay(contexto.Input); contexto.Camara = new Core.Camara.TgcCamera(); lookAt = new TGCVector3(0, 50, 400); contexto.Camara.SetCamera(new TGCVector3(lookAt.X, lookAt.Y, lookAt.Z + 30), lookAt); botones.Add( new Boton(new TGCVector3(lookAt.X, lookAt.Y + 6, lookAt.Z), "Jugar", Color.Green, 300, () => { contexto.Empezar(); }) ); botones.Add( new Boton(new TGCVector3(lookAt.X, lookAt.Y, lookAt.Z), "Salir", Color.Red, 25, () => { Environment.Exit(0); }) ); contexto.cancionPpal.play(true); }
public Ray(TgcD3dInput input) { Input = input; pickingRay = new TgcPickingRay(Input); }
public override void Update() { var velocidadCaminar = 25f * ElapsedTime; //Calcular proxima posicion de personaje segun Input var moving = false; var movement = TGCVector3.Empty; //Adelante if (Input.keyDown(Key.W)) { movement.Z = velocidadCaminar; moving = true; } //Atras if (Input.keyDown(Key.S)) { movement.Z = -velocidadCaminar; moving = true; } //Derecha if (Input.keyDown(Key.D)) { movement.X = velocidadCaminar; moving = true; } //Izquierda if (Input.keyDown(Key.A)) { movement.X = -velocidadCaminar; moving = true; } //Si hubo desplazamiento if (moving) { //Aplicar movimiento colliderCylinder.Center += movement; colliderCylinderFixedY.Center += movement; personaje.Position += movement; //Activar animacion de caminando personaje.playAnimation("Caminando", true); } else { //Si no se esta moviendo, activar animacion de Parado personaje.playAnimation("Parado", true); } var size = sizeModifier.Value; var rotation = rotationModifier.Value; //Se tienen dos coliders, un cilindro con rotacion y otro orientado al eje Y. colliderCylinder.Rotation = rotation; colliderCylinder.Radius = size.X; colliderCylinder.Length = size.Y; //Actualizar este cilindro es mas costoso. colliderCylinder.updateValues(); //Cilindro sin rotacion, para ser utilizado con personajes. colliderCylinderFixedY.Radius = size.X; colliderCylinderFixedY.Length = size.Y; //Un cilindro orientado es facil de actualizar. colliderCylinderFixedY.updateValues(); if (fixedYModifier.Value) { //Test de colisiones del cilindro orientado en Y, al ser mucho mas simple tiene mas test soportados por el framework. if (TgcCollisionUtils.testSphereCylinder(collisionableSphere, colliderCylinderFixedY)) { collisionableSphere.setRenderColor(collisionColor); } else { collisionableSphere.setRenderColor(noCollisionColor); } if (TgcCollisionUtils.testAABBCylinder(collisionableMeshAABB.BoundingBox, colliderCylinderFixedY)) { collisionableMeshAABB.BoundingBox.setRenderColor(collisionColor); } else { collisionableMeshAABB.BoundingBox.setRenderColor(noCollisionColor); } if (TgcCollisionUtils.testCylinderCylinder(collisionableCylinder, colliderCylinderFixedY)) { collisionableCylinder.setRenderColor(collisionColor); } else { collisionableCylinder.setRenderColor(noCollisionColor); } if (pickingTimeLeft > 0) { pickingTimeLeft -= ElapsedTime; } else { colliderCylinderFixedY.setRenderColor(noCollisionColor); } if (Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT)) { var pickingRay = new TgcPickingRay(Input); pickingRay.updateRay(); if (TgcCollisionUtils.testRayCylinder(pickingRay.Ray, colliderCylinderFixedY)) { pickingTimeLeft = PICKING_TIME; colliderCylinderFixedY.setRenderColor(pickingColor); } } } else { //Test de colisiones del cilindro, la cantidad de test que tiene el framewor es acotada. if (TgcCollisionUtils.testSphereCylinder(collisionableSphere, colliderCylinder)) { collisionableSphere.setRenderColor(collisionColor); } else { collisionableSphere.setRenderColor(noCollisionColor); } if (pickingTimeLeft > 0) { pickingTimeLeft -= ElapsedTime; } else { colliderCylinder.setRenderColor(noCollisionColor); } if (Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT)) { var pickingRay = new TgcPickingRay(Input); pickingRay.updateRay(); if (TgcCollisionUtils.testRayCylinder(pickingRay.Ray, colliderCylinder)) { pickingTimeLeft = PICKING_TIME; colliderCylinder.setRenderColor(pickingColor); } } } //Hacer que la camara siga al personaje en su nueva posicion camaraInterna.Target = personaje.Position; }
public bool CheckRayCollision(TgcPickingRay pickingRay) { return(Meshes.Any(mesh => TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, mesh.BoundingBox, out TGCVector3 collisionPoint))); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; time = new DateTime(); //GuiController.Instance.D3dDevice.RenderState.ReferenceAlpha =255; TgcTexture texe = TgcTexture.createTexture(d3dDevice, "mitex1", GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\granito00.jpg"); TgcTexture texe1 = TgcTexture.createTexture(d3dDevice, "mitex1", GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\nubes.jpg"); Vector3 cen = new Vector3(1, 1, 220); Vector3 boxSi = new Vector3(2000, 2000, 2000); cajaporon = BoundingBoxExtendida.fromSize(cen, boxSi, texe1); TgcSceneLoader loader = new TgcSceneLoader(); boxes = new List <BoundingBoxExtendida>(); int a = 0; Vector3 boxSize = new Vector3(25, 25, 25); //Genera la aleatoriedad this.generarAleatorio(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { if (!((k == 1 || k == 2) && ((i > 0 && i < 3) && (j > 0 && j < 3)))) { TgcTexture texture = TgcTexture.createTexture(d3dDevice, "mitex" + i + j + k, GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\granito00.jpg"); Vector3 center = new Vector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, (k * 35) + 220); BoundingBoxExtendida box1 = BoundingBoxExtendida.fromSize(center, boxSize, texture); box1.setName("imagen" + imagenes[a]); a++; boxes.Add(box1); } } } } //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); GuiController.Instance.RotCamera.CameraDistance = 250; GuiController.Instance.RotCamera.CameraCenter = new Vector3(56.25f, 56.25f, 272.2f); //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TgcBox.fromSize(new Vector3(25, 25, 25), Color.Red); selected = false; //Crear caja para indicar ubicacion de la luz ligtBox = TgcBox.fromSize(new Vector3(10, 10, 10), Color.Yellow); aciertosText = new TgcText2d(); aciertosText.Text = "Aciertos:"; aciertosText.Position = new Point(340, 10); aciertosText.Color = Color.Red; aciertosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 20, FontStyle.Bold)); fracazosText = new TgcText2d(); fracazosText.Text = "Fracasos:"; fracazosText.Position = new Point(340, 90); fracazosText.Color = Color.Red; fracazosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 20, FontStyle.Bold)); puntuacionAciertosText = new TgcText2d(); puntuacionAciertosText.Text = "0"; puntuacionAciertosText.Position = new Point(340, 40); puntuacionAciertosText.Color = Color.Red; puntuacionAciertosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 40, FontStyle.Bold)); puntuacionFracazosText = new TgcText2d(); puntuacionFracazosText.Text = "0"; puntuacionFracazosText.Position = new Point(340, 110); puntuacionFracazosText.Color = Color.Red; puntuacionFracazosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 40, FontStyle.Bold)); finalText = new TgcText2d(); finalText.Text = "FIN DEL JUEGO"; finalText.Position = new Point(0, 30); finalText.Color = Color.Red; finalText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 70, FontStyle.Bold)); finalText1 = new TgcText2d(); finalText1.Position = new Point(0, 120); finalText1.Color = Color.Red; finalText1.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 60, FontStyle.Bold)); tiempoTranscurrido = new TgcText2d(); tiempoTranscurrido.Position = new Point(0, 360); tiempoTranscurrido.Color = Color.Red; tiempoTranscurrido.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 60, FontStyle.Bold)); this.loadMp3(GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\dalePlay.mp3"); TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); player.play(true); GuiController.Instance.Modifiers.addButton("Reload", "Reload", new EventHandler(Reload_ButtonClick)); //Crear Sprite animado animatedSprite = new MySprite( GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\prueba2.png", //Textura de 256x256 new Size(128, 128), //Tamaño de un frame (64x64px en este caso) 16, //Cantidad de frames, (son 16 de 64x64px) 6 //Velocidad de animacion, en cuadros x segundo ); //Ubicarlo centrado en la pantalla Size screenSize = GuiController.Instance.Panel3d.Size; Size textureSize = animatedSprite.Sprite.Texture.Size; animatedSprite.Scaling = new Vector2(4f, 4f); animatedSprite.Position = new Vector2(screenSize.Width / 2 - textureSize.Width / 2, screenSize.Height / 2 - textureSize.Height / 2); animatedSprite.positionBkp = animatedSprite.Position; //Crear Sprite animado animatedSpriteTriste = new MySprite( GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\caritaTiste.png", //Textura de 256x256 new Size(128, 128), //Tamaño de un frame (64x64px en este caso) 16, //Cantidad de frames, (son 16 de 64x64px) 6 //Velocidad de animacion, en cuadros x segundo ); animatedSpriteTriste.Scaling = new Vector2(2f, 2f); animatedSpriteTriste.Position = new Vector2(8, 5); animatedSpriteTriste.positionBkp = animatedSpriteTriste.Position; }