示例#1
0
        /// <summary>
        /// Dibujar el esqueleto de la malla
        /// </summary>
        protected void renderSkeletonMesh()
        {
            Device  device  = GuiController.Instance.D3dDevice;
            Vector3 ceroVec = new Vector3(0, 0, 0);

            //Dibujar huesos y joints
            for (int i = 0; i < bones.Length; i++)
            {
                TgcSkeletalBone bone = bones[i];

                //Renderizar Joint
                TgcBox jointBox = skeletonRenderJoints[i];
                jointBox.Transform = bone.MatFinal * this.transform;
                jointBox.render();

                //Modificar línea del bone
                if (bone.ParentBone != null)
                {
                    TgcLine boneLine = skeletonRenderBones[i];

                    boneLine.PStart = TgcVectorUtils.transform(ceroVec, bone.MatFinal * this.transform);
                    boneLine.PEnd   = TgcVectorUtils.transform(ceroVec, bone.ParentBone.MatFinal * this.transform);
                    boneLine.updateValues();
                }
            }

            //Dibujar bones
            foreach (TgcLine boneLine in skeletonRenderBones)
            {
                if (boneLine != null)
                {
                    boneLine.render();
                }
            }
        }
示例#2
0
        public void renderAndDeform()
        {
            if (lastFrameDrawn != g.game.actualFrame)
            {
                lastFrameDrawn = g.game.actualFrame;

                render();
                deform();

                if (false) //@todo agregar boton
                {
                    foreach (var par in parallelipeds)
                    {
                        Action <TGCVector3, Color> drawLine = (v, c) =>
                        {
                            var p1 = v * 1; p1.Y = -40000;
                            var p2 = v * 1; p2.Y = 4000;

                            var line = TgcLine.fromExtremes(p1, p2);
                            line.Color = c;
                            line.updateValues();
                            line.Render();
                        };

                        foreach (var vertex in par.transformedVertex)
                        {
                            drawLine(vertex, Color.Gold);
                        }

                        Action <int, int, float> drawExtraVertexFall = (v1, v2, w1) =>
                        {
                            float w2     = 1f - w1;
                            var   vertex = new TGCVector3(par.transformedVertex[v1].X * w1 + par.transformedVertex[v2].X * w2,
                                                          0,
                                                          par.transformedVertex[v1].Z * w1 + par.transformedVertex[v2].Z * w2);
                            drawLine(vertex, Color.BlanchedAlmond);
                        };

                        drawExtraVertexFall(0, 4, .5f);
                        drawExtraVertexFall(0, 1, .5f);
                        drawExtraVertexFall(1, 5, .5f);
                        drawExtraVertexFall(4, 5, .5f);//@optim puede que tirar vertex del piso no sea necesario, ver al final

                        drawExtraVertexFall(2, 6, .5f);
                        drawExtraVertexFall(2, 3, .5f);
                        drawExtraVertexFall(3, 7, .5f);
                        drawExtraVertexFall(6, 7, .5f);

                        drawExtraVertexFall(2, 7, .5f);
                        drawExtraVertexFall(2, 7, .25f);
                        drawExtraVertexFall(2, 7, .75f);

                        drawExtraVertexFall(4, 1, .5f);
                        drawExtraVertexFall(4, 1, .25f);
                        drawExtraVertexFall(4, 1, .75f);
                    }
                }
            }
        }
示例#3
0
        public void Render()
        {
            shader.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.FromArgb(0, candlesPlaced < 6?0:(candlesPlaced - 6), 0, 0)));

            shader.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(g.camera.eyePosition));
            shader.SetValue("lightIntensityEye", 50f + (g.hands.state > 0?
                                                        (g.hands.state == 1?
                                                         250f + Random.Next(-50, 50)
                                                                : 250f + Random.Next(-50, 50) + 250f + Random.Next(-50, 50))
                                                     :0));

            for (int i = 0; i < lightCount; i++)
            {
                //lightPos del frame anterior
                shader.SetValue("lightPosition[" + i.ToString() + "]", TGCVector3.Vector3ToFloat4Array(lightPosition[i]));
                shader.SetValue("lightIntensity[" + i.ToString() + "]", 250f + Random.Next(-50, 50));

                //de paso limpio la lightpos para cargar las de este frame
                lightPosition[i] = TGCVector3.One * float.MaxValue;
            }

            lightIndex = 0;

            sky.Render();
            if (renderCandlePlace)
            {
                renderCandles();
            }
            g.chunks.render();



            if (GameModel.debugColission)
            {
                g.chunks.fromCoordinates(g.camera.eyePosition).renderDebugColission();
                TGCVector3 ray = g.camera.horx.Origin + TGCVector3.Down * 200f;
                TGCVector3 end = ray + g.camera.horx.Direction * 200f;

                TgcLine.fromExtremes(ray, end).Render();

                ray = g.camera.horz.Origin + TGCVector3.Down * 200f;
                end = ray + g.camera.horz.Direction * 200f;

                TgcLine.fromExtremes(ray, end).Render();
            }

            g.terrain.Render();

            deforming += g.game.ElapsedTime * 0.1f;
            //Console.WriteLine(deforming);
        }
示例#4
0
        public void renderCandles()
        {
            var scale = TGCMatrix.Scaling(new TGCVector3(10, 15, 10));

            for (int i = 0; i < candlesPlaced; i++)
            {
                candleMesh.Transform = scale * TGCMatrix.Translation(candlePlaceVertex[i]);
                candleMesh.Render();

                maybeLightCandleAt(candlePlaceVertex[i]);

                for (int j = 0; j < i; j++)
                {
                    TgcLine.fromExtremes(candlePlaceVertex[i], candlePlaceVertex[j], Color.Red).Render();
                }
            }
        }
示例#5
0
        /// <summary>
        /// Crear todas las estructuras de debug
        /// </summary>
        public void init()
        {
            int bonesCount = Enum.GetValues(typeof(JointType)).Length;

            //Crear joints
            jointBoxes = new TgcBox[bonesCount];
            for (int i = 0; i < jointBoxes.Length; i++)
            {
                jointBoxes[i] = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(JOINT_SIZE, JOINT_SIZE, JOINT_SIZE), Color.Red);
            }

            //Crear bones
            jointLines = new TgcLine[bonesCount];
            for (int i = 0; i < jointLines.Length; i++)
            {
                jointLines[i]       = new TgcLine();
                jointLines[i].Color = Color.Green;
            }
        }
示例#6
0
        public void render()
        {
            updateMesh();

            mesh.Effect = Meshc.actualShader;
            mesh.Effect.SetValue("type", 2);
            mesh.Technique = Meshc.actualTechnique;

            mesh.Render();

            if (GameModel.debugSqueleton)
            {
                TgcLine.fromExtremes(cPos, cPos + colDir, Color.Red).Render();
                TGCVector3 cross = TGCVector3.Cross(colDir, TGCVector3.Up);
                TgcLine.fromExtremes(cPos, cPos + cross * sidePref, Color.Green).Render();

                var lightObj    = new TGCVector3(g.mostro.lightObj.X, g.mostro.flyHeight, g.mostro.lightObj.Y);
                var lightObjObj = new TGCVector3(g.mostro.lightObjObj.X, g.mostro.flyHeight, g.mostro.lightObjObj.Y);
                TgcLine.fromExtremes(lightObj - TGCVector3.Up * 10000f, lightObj + TGCVector3.Up * 10000f, Color.Green).Render();
                TgcLine.fromExtremes(lightObjObj - TGCVector3.Up * 10000f, lightObjObj + TGCVector3.Up * 10000f, Color.Red).Render();
            }
        }
示例#7
0
        /// <summary>
        /// Crea mallas a modo Debug para visualizar la configuración del esqueleto
        /// </summary>
        public void buildSkletonMesh()
        {
            //Crear array para dibujar los huesos y joints
            Color   jointsColor = Color.Violet;
            Color   bonesColor  = Color.Yellow;
            Vector3 jointsSize  = new Vector3(2, 2, 2);
            Vector3 ceroVec     = new Vector3(0, 0, 0);

            skeletonRenderJoints = new TgcBox[bones.Length];
            skeletonRenderBones  = new TgcLine[bones.Length];
            int boneColor = Color.Yellow.ToArgb();

            //Actualizar jerarquia
            for (int i = 0; i < bones.Length; i++)
            {
                TgcSkeletalBone bone = bones[i];

                //Es hijo o padre
                if (bone.ParentBone == null)
                {
                    skeletonRenderBones[i] = null;
                }
                else
                {
                    //Crear linea de hueso para renderziar esqueleto
                    TgcLine boneLine = new TgcLine();
                    boneLine.PStart        = TgcVectorUtils.transform(ceroVec, bone.MatFinal);
                    boneLine.PEnd          = TgcVectorUtils.transform(ceroVec, bone.ParentBone.MatFinal);
                    boneLine.Color         = bonesColor;
                    skeletonRenderBones[i] = boneLine;
                }
                //Crear malla de Joint para renderizar el esqueleto
                TgcBox jointBox = TgcBox.fromSize(jointsSize, jointsColor);
                jointBox.AutoTransformEnable = false;
                skeletonRenderJoints[i]      = jointBox;
            }
        }
示例#8
0
        /// <summary>
        ///     Crea mallas a modo Debug para visualizar la configuración del esqueleto
        /// </summary>
        public void buildSkletonMesh()
        {
            //Crear array para dibujar los huesos y joints
            var jointsColor = Color.Violet;
            var bonesColor  = Color.Yellow;
            var jointsSize  = new TGCVector3(2, 2, 2);
            var ceroVec     = TGCVector3.Empty;

            skeletonRenderJoints = new TGCBox[bones.Length];
            skeletonRenderBones  = new TgcLine[bones.Length];
            var boneColor = Color.Yellow.ToArgb();

            //Actualizar jerarquia
            for (var i = 0; i < bones.Length; i++)
            {
                var bone = bones[i];

                //Es hijo o padre
                if (bone.ParentBone == null)
                {
                    skeletonRenderBones[i] = null;
                }
                else
                {
                    //Crear linea de hueso para renderziar esqueleto
                    var boneLine = new TgcLine();
                    boneLine.PStart        = TGCVector3.transform(ceroVec, bone.MatFinal);
                    boneLine.PEnd          = TGCVector3.transform(ceroVec, bone.ParentBone.MatFinal);
                    boneLine.Color         = bonesColor;
                    skeletonRenderBones[i] = boneLine;
                }
                //Crear malla de Joint para renderizar el esqueleto
                var jointBox = TGCBox.fromSize(jointsSize, jointsColor);
                jointBox.AutoTransform  = false;
                skeletonRenderJoints[i] = jointBox;
            }
        }
 public Debug_Draw_Bullet()
 {
     linea = new TgcLine();
 }
 public DebugDrawerTest()
 {
     linea = new TgcLine();
 }
示例#11
0
        public void render()
        {
            //por ahora lo dejo aca a este codigo
            //se separa la transformacion de el render porque la transformacion aplica a chunks que no estan siendo
            //renderizados tambien. Ahora se recorren todos, en la version final se van a actualizar algunos con
            //distintas tranformaciones


            int chunksRendered = 0;

            var eyeDir = g.camera.cameraRotatedTarget;

            eyeDir.Y = 0;//ignorar y
            eyeDir.Normalize();

            var ortogDir = TGCVector3.Cross(eyeDir, TGCVector3.Up);


            //la idea inicial es tener un generar una cuadricula del tamaño de chunk con estos 2 vectores como base
            //y por cada interseccion conseguir el chunk y renderizarlo
            //funciona si los puntos estan alineados con los chunks, si no lo estan puede haber 2 puntos por chunk
            //o ninguno.
            //si se avanza por chunkLen * 1 / sqrt( 2 ) se asegura que no va a haber agujeros, pero se va a estar
            //tocando los chunks con 2 puntos casi siempre, pero bueno. Para no renderizar 2 veces controlo que
            //el ultimo frame de renderizado no sea el actual.


            //el factor de avance podría estar en funcion de que tan alineado se esta, siendo 1 si se esta alineado
            //y 1/sqrt(2) si se esta totalmente desalineado.
            //float distFactor = 0.707f + (float)Math.Abs(Math.Cos(Camera.Camera.leftrightRot * 2f))* (1f-0.707f);

            float distFactor = 0.707f;

            Action <int, int> drawHor = (along, side) =>
            {
                for (int j = -side; j <= side; j++)
                {
                    var pos = eyeDir * chunkLen * along * distFactor
                              + ortogDir * chunkLen * j * distFactor
                              + g.camera.eyePosition;


                    Chunk c = fromCoordinates(pos);
                    if (c != null)
                    {
                        c.render();
                        chunksRendered++;
                        if (GameModel.debugChunks)
                        {
                            var p1 = pos * 1; p1.Y = -40000;
                            var p2 = pos * 1; p2.Y = 4000;

                            var line = TgcLine.fromExtremes(p1, p2);
                            line.Color = Color.BlanchedAlmond;
                            line.Render();
                            c.renderDebug();
                        }
                    }
                }
            };

            //@todo agregar version hd que suma mas

            //@todo se podrían dibujar los chunks lejanos solo si hay alguna luz ahi, teniendo en cuenta
            //tambien los entremedios

            drawHor(-2, 1);
            drawHor(-1, 2);
            int cutOut = 8;

            for (int i = 0; i < cutOut; i++)
            {
                drawHor(i, (i + 1) / 2 + 1);
            }
            for (int i = cutOut; i < 18; i++)
            {
                drawHor(i, 6);
            }


            /*var size = 9;
             * for(float i=-size;i<size+1;i+=.707f)
             *  for(float j = -size; j < size+1; j+=.707f)
             *  {
             *      var pos = eyeDir * chunkLen * i + ortogDir * chunkLen * j;// + g.camera.eyePosition;
             *
             *      var p1 = pos * 1;p1.Y = -40000;
             *      var p2 = pos * 1;p2.Y = 4000;
             *
             *      var line = TgcLine.fromExtremes(p1, p2);
             *      line.Color=Color.BlanchedAlmond;
             *      line.Render();
             *
             *
             *
             *      Chunk c = fromCoordinates(pos);
             *      if (c != null)
             *      {
             *          c.render();
             *          chunksRendered++;
             *      }
             *  }*/



            //Console.WriteLine(chunksRendered.ToString());



            //foreach (Chunk chunk in chunks)
            //{
            //        foreach (Meshc meshc in chunk.meshes)
            //        {
            //            meshc.transform(matriz);
            //            meshc.mesh.Render();
            //            //meshc.paralleliped.renderAsPolygons();
            //        }
            //}


            //foreach (Meshc meshc in fromCoordinates(camera.eyePosition).meshes)
            //{
            //    meshc.transform(matriz);
            //    meshc.mesh.Render();
            //    meshc.paralleliped.renderAsPolygons();
            //}
        }