Exemplo n.º 1
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);
                    }
                }
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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();
            //}
        }