コード例 #1
0
ファイル: LightHandler.cs プロジェクト: Erlisch/Caliginous
        /// <summary>
        /// Checks which lights are visible on screen and sends them to the shader.
        /// </summary>
        /// <param name="windowwidth"></param>
        /// <param name="windowheight"></param>
        /// <param name="cam"></param>
        /// <param name="progid"></param>
        public static void SendVisibleLightsToShader(int windowwidth, int windowheight, Camera cam)
        {
            int screenx = ((int)cam.Position.X - (windowwidth / 2)), screeny = ((int)cam.Position.Y - (windowheight / 2));
            //int screenright = (screenx + windowwidth), screentop = (screeny + windowheight);
            //int right = (int)(posV3.X + dimV2.X), top = (int)(posV3.Y + dimV2.Y);

            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            for(int i = 0; i < numLights_I; ++i) { //Lägg till alla för tillfället

                //Array.Copy(lights_ArLig[i].PositionMinRadFAR, 0, posMinRad_ArF, (i * 4), 4);
                //Array.Copy(lights_ArLig[i].ColorExtraSizeFAR, 0, colExtraSize_ArF, (i * 4), 4);
                //Buffer.BlockCopy(lights_ArLig[i].PositionMinRadFAR, 0, posMinRad_ArF, ((i * 4) * sizeof(float)), (4 * sizeof(float)));
                //Buffer.BlockCopy(lights_ArLig[i].ColorExtraSizeFAR, 0, colExtraSize_ArF, ((i * 4) * sizeof(float)), (4 * sizeof(float)));

                posMinRad_ArF[(i * 4)] = lights_ArLig[i].PositionMinRad.X;
                posMinRad_ArF[(i * 4) + 1] = lights_ArLig[i].PositionMinRad.Y;
                posMinRad_ArF[(i * 4) + 2] = lights_ArLig[i].PositionMinRad.Z;
                posMinRad_ArF[(i * 4) + 3] = lights_ArLig[i].PositionMinRad.W;

                colExtraSize_ArF[(i * 4)] = lights_ArLig[i].ColorExtraSize.X;
                colExtraSize_ArF[(i * 4) + 1] = lights_ArLig[i].ColorExtraSize.Y;
                colExtraSize_ArF[(i * 4) + 2] = lights_ArLig[i].ColorExtraSize.Z;
                colExtraSize_ArF[(i * 4) + 3] = lights_ArLig[i].ColorExtraSize.W;
            }
            //sw.Stop();
            //Console.WriteLine("Time: " + sw.ElapsedMilliseconds.ToString() + "ms.");
            /*GL.Uniform1(uniformNumLights_I, numLights_I);
            GL.Uniform4(uniformLightsPosMinRad_I, (10 * 4), posMinRad_ArF);
            GL.Uniform4(uniformLightColExtraSize_I, (10 * 4), colExtraSize_ArF);*/

            //test = { GetLight(0).X, GetLight(0).Y };
            if(numLights_I > 0) {
                //test[0] = GetLight(0).X; test[1] = GetLight(0).Y;
                //GL.Uniform2(ulightpos_I, (2 * 4), test);
                Vector2 test = new Vector2(GetLight(0).X, GetLight(0).Y);
                GL.Uniform2(ulightpos_I, test);
            }
        }
コード例 #2
0
ファイル: Quad.cs プロジェクト: Erlisch/Caliginous
        /// <summary>
        /// This draw method checks if the Quad is inside the window and calls the normal Draw() if it is.
        /// 
        /// Denna draw metod kollar om Quad:en har nån del innuti fönstret
        /// Om den har det så kallas vanliga Draw(), annars så gör ingenting
        /// Simulerar VFC - eftersom vi bara är i 2D (och OGL context:et bör täcka hela fönstret här) så är denna koll nog billigare än att göra riktig VFC (blev dock mer uträkningar än väntat pga. kameran...)
        /// OBS: Fungerar bara i Ortho (och om OpenGL context:en är lika stor som fönstret?)
        /// </summary>
        /// <param name="windowwidth"></param>
        /// <param name="windowheight"></param>
        /// <param name="cam"></param>
        /// <param name="ScaleFactor"></param>
        /// <param name="rotz"></param>
        /// <param name="StaticPos"></param>
        /// <param name="FromBatcher"></param>
        public void Draw(int windowwidth, int windowheight, Camera cam, float ScaleFactor = 1f, float rotz = 0.0f/*, bool ShadowPass = false*/, bool StaticPos = false, bool FromBatcher = false)
        {
            //UPPDATERA SÅ DEN KOLLAR MED SKALNINGEN OCKSÅ????
            int screenx, screeny, screenright, screentop;
            int right, top;

            //if(ShadowPass && !shadowCaster_B) { return; } //If doing a shadowpass and this drawable is not a shadowcaster - abort/skip!

            screenx = ((int)cam.Position.X - (windowwidth / 2));
            screeny = ((int)cam.Position.Y - (windowheight / 2));
            screenright = (screenx + windowwidth);
            screentop = (screeny + windowheight);
            right = (int)(pos_V3.X + dim_V2.X);
            top = (int)(pos_V3.Y + dim_V2.Y);

            //http://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other
            //http://silentmatt.com/rectangle-intersection/
            //if(A.x1 < B.x2 && A.x1 > B.x1 && A.y1 < B.y2 && A.y2 > B.y1)
            if(((dim_V2.X > windowwidth) || (dim_V2.Y > windowheight)) //If bigger than the window
               || ((screenx < right) && (screenright > pos_V3.X) && (screeny < top) && (screentop > pos_V3.Y))) { //If (partly) inside the window
                Draw(ScaleFactor, 0.0f, 0.0f, rotz, StaticPos, FromBatcher);
            }
        }