Exemplo n.º 1
0
 /// <summary>
 /// Setzt die Partikelfärbung
 /// </summary>
 /// <param name="red">Rot</param>
 /// <param name="green">Grün</param>
 /// <param name="blue">Blau</param>
 /// <param name="intensity">Helligkeit</param>
 public void SetColor(float red, float green, float blue, float intensity)
 {
     _tint.X = HelperGL.Clamp(red, 0, 1);
     _tint.Y = HelperGL.Clamp(green, 0, 1);
     _tint.Z = HelperGL.Clamp(blue, 0, 1);
     _tint.W = HelperGL.Clamp(intensity, 0, 1);
 }
Exemplo n.º 2
0
 public void SetBloom(float red, float green, float blue, float intensity)
 {
     _bloom.X = HelperGL.Clamp(red, 0, 1);
     _bloom.Y = HelperGL.Clamp(green, 0, 1);
     _bloom.Z = HelperGL.Clamp(blue, 0, 1);
     _bloom.W = HelperGL.Clamp(intensity, 0, 1);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Setzt die Farbe des Sonnenlichts
 /// </summary>
 /// <param name="red">Rotanteil</param>
 /// <param name="green">Grünanteil</param>
 /// <param name="blue">Blauanteil</param>
 /// <param name="intensity">Helligkeitsanteil</param>
 public void SetSunColor(float red, float green, float blue, float intensity)
 {
     _sunColor.X = HelperGL.Clamp(red, 0, 1);
     _sunColor.Y = HelperGL.Clamp(green, 0, 1);
     _sunColor.Z = HelperGL.Clamp(blue, 0, 1);
     _sunColor.W = HelperGL.Clamp(intensity, 0, 1);
 }
Exemplo n.º 4
0
 internal void SetTextureBackgroundInternal(string filename, float repeatX = 1, float repeatY = 1, float red = 1, float green = 1, float blue = 1, float intensity = 1, bool isFile = true)
 {
     if (filename == null || filename.Length < 1)
     {
         _textureBackground     = -1;
         _textureBackgroundTint = Vector4.Zero;
     }
     else
     {
         if (KWEngine.CustomTextures[this].ContainsKey(filename))
         {
             _textureBackground = KWEngine.CustomTextures[this][filename];
         }
         else
         {
             _textureBackground = isFile ? HelperTexture.LoadTextureForBackgroundExternal(filename) : HelperTexture.LoadTextureForBackgroundInternal(filename);
             KWEngine.CustomTextures[this].Add(filename, _textureBackground);
         }
         _textureBackgroundTint.X      = HelperGL.Clamp(red, 0, 1);
         _textureBackgroundTint.Y      = HelperGL.Clamp(green, 0, 1);
         _textureBackgroundTint.Z      = HelperGL.Clamp(blue, 0, 1);
         _textureBackgroundTint.W      = HelperGL.Clamp(intensity, 0, 1);
         _textureBackgroundTransform.X = HelperGL.Clamp(repeatX, 0.001f, 8192);
         _textureBackgroundTransform.Y = HelperGL.Clamp(repeatY, 0.001f, 8192);
         _textureSkybox = -1;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Glow-Effekt des Objekts
 /// </summary>
 /// <param name="red">Rot</param>
 /// <param name="green">Grün</param>
 /// <param name="blue">Blau</param>
 /// <param name="intensity">Intensität</param>
 public void SetGlow(float red, float green, float blue, float intensity)
 {
     _glow.X = HelperGL.Clamp(red, 0, 1);
     _glow.Y = HelperGL.Clamp(green, 0, 1);
     _glow.Z = HelperGL.Clamp(blue, 0, 1);
     _glow.W = HelperGL.Clamp(intensity, 0, 1);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Setzt die Größe
 /// </summary>
 /// <param name="width">Breite</param>
 /// <param name="height">Höhe</param>
 public void SetScale(float width, float height)
 {
     _scale.X     = HelperGL.Clamp(width, 0.001f, float.MaxValue);
     _scale.Y     = HelperGL.Clamp(height, 0.001f, float.MaxValue);
     _scale.Z     = 1;
     _scaleMatrix = Matrix4.CreateScale(_scale);
     UpdatePositions();
 }
Exemplo n.º 7
0
 private void SetFOVShadowPrivate(float fov)
 {
     FOVShadow2 = HelperGL.Clamp(fov, 60, 179);
     if (KWEngine.CurrentWorld != null)
     {
         _projectionMatrixShadow2 = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(FOVShadow2 / 2), KWEngine.ShadowMapSize / (float)KWEngine.ShadowMapSize, 1f, CurrentWorld != null ? CurrentWorld.ZFar / 10 : 100f);
         UpdateMatrices();
     }
 }
Exemplo n.º 8
0
        internal override void Draw(GameObject g, ref Matrix4 viewProjection, ref Matrix4 viewProjectionShadowBiased, ref Matrix4 viewProjectionShadowBiased2, HelperFrustum frustum, ref float[] lightColors, ref float[] lightTargets, ref float[] lightPositions, int lightCount, ref int lightShadow)
        {
            if (g == null || !g.HasModel || g.CurrentWorld == null || g.Opacity <= 0)
            {
                return;
            }

            g.IsInsideScreenSpace = frustum.SphereVsFrustum(g.GetCenterPointForAllHitboxes(), g.GetMaxDiameter() / 2);
            if (!g.IsInsideScreenSpace)
            {
                return;
            }

            GL.UseProgram(mProgramId);

            lock (g)
            {
                int index = 0;
                foreach (string meshName in g.Model.Meshes.Keys)
                {
                    if (g._cubeModel is GeoModelCube6)
                    {
                        index = 0;
                    }
                    Matrix4.Mult(ref g.ModelMatrixForRenderPass[index], ref viewProjection, out _modelViewProjection);
                    GL.UniformMatrix4(mUniform_MVP, false, ref _modelViewProjection);
                    index++;

                    GL.Disable(EnableCap.Blend);
                    GeoMesh mesh = g.Model.Meshes[meshName];
                    if (mesh.Material.Opacity <= 0)
                    {
                        continue;
                    }


                    if (g._cubeModel != null)
                    {
                        UploadMaterialForKWCube(g._cubeModel, mesh, g);
                    }
                    else
                    {
                        GL.Uniform3(mUniform_BaseColor, mesh.Material.ColorDiffuse.X, mesh.Material.ColorDiffuse.Y, mesh.Material.ColorDiffuse.Z);
                    }
                    HelperGL.CheckGLErrors();
                    GL.BindVertexArray(mesh.VAO);
                    GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                    GL.DrawElements(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, 0);
                    HelperGL.CheckGLErrors();
                    GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
                    GL.BindVertexArray(0);
                }
            }

            GL.UseProgram(0);
        }
Exemplo n.º 9
0
 public static void SoundChangeGain(int sourceId, float gain)
 {
     if (mAudioOn)
     {
         gain = HelperGL.Clamp(gain, 0, 8);
         if (mSources[sourceId] != null && mSources[sourceId].IsPlaying)
         {
             AL.Source(mSources[sourceId].GetSourceId(), ALSourcef.Gain, gain);
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Setzt den Koeffizienten für die Berechnung der Schatten der LightObject-Instanz
 /// </summary>
 /// <param name="bias">Biaswert (Standard: 0.005f; Bereich: 0.00001f bis 1f)</param>
 public void SetFOVShadowBiasCoefficient(float bias = 0.005f)
 {
     if (Type != LightType.DirectionalShadow)
     {
         throw new Exception("Cannot set FOV for a LightObject that is not of Type 'DirectionalShadow'.");
     }
     else
     {
         ShadowMapBiasCoefficient = HelperGL.Clamp(bias, 0.00001f, 1);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Konstruktormethode für Partikel
        /// </summary>
        /// <param name="position">Position</param>
        /// <param name="scale">Größe in x-, y- und z-Richtung</param>
        /// <param name="type">Art</param>
        public ParticleObject(Vector3 position, Vector3 scale, ParticleType type)
        {
            _scale.X        = HelperGL.Clamp(scale.X, 0.001f, float.MaxValue);
            _scale.Y        = HelperGL.Clamp(scale.Y, 0.001f, float.MaxValue);
            _scale.Z        = HelperGL.Clamp(scale.Z, 0.001f, float.MaxValue);
            _scaleCurrent.X = HelperGL.Clamp(scale.X, 0.001f, float.MaxValue);
            _scaleCurrent.Y = HelperGL.Clamp(scale.Y, 0.001f, float.MaxValue);
            _scaleCurrent.Z = HelperGL.Clamp(scale.Z, 0.001f, float.MaxValue);

            Position = position;

            _type = type;

            _info = KWEngine.ParticleDictionary[_type];
        }
Exemplo n.º 12
0
 /// <summary>
 /// Setzt das Field of View (in Grad) für das schattenwerfende Licht (DirectionalShadow)
 /// </summary>
 /// <param name="fov">Blickfeld nach links und rechts in Grad (Minimum: 60, Maximum: 180)</param>
 public void SetFOVShadow(float fov)
 {
     if (Type != LightType.DirectionalShadow)
     {
         throw new Exception("Cannot set FOV for a LightObject that is not of Type 'DirectionalShadow'.");
     }
     else
     {
         FOVShadow2 = HelperGL.Clamp(fov, 60, 179);
         if (KWEngine.CurrentWorld != null)
         {
             _projectionMatrixShadow2 = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(FOVShadow2 / 2), KWEngine.ShadowMapSize / (float)KWEngine.ShadowMapSize, 1f, CurrentWorld != null ? CurrentWorld.ZFar / 10 : 100f);
             UpdateMatrices();
         }
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Prüft, ob der Mauszeiger auf dem HUD-Objekt ist
        /// </summary>
        /// <param name="ms">Mausinfo</param>
        /// <returns>true, wenn die Maus auf dem HUD-Objekt ist</returns>
        public bool IsMouseCursorOnMe(MouseState ms)
        {
            GLWindow w = KWEngine.CurrentWindow;

            if (w._windowRect.Contains(ms.X, ms.Y))
            {
                Vector2 coords = HelperGL.GetNormalizedMouseCoords(ms.X, ms.Y, w);
                float   left, right, top, bottom;

                if (_type == HUDObjectType.Image)
                {
                    left  = _absolute.X - _scale.X * 0.5f;
                    right = _absolute.X + _scale.X * 0.5f;

                    top    = _absolute.Y - _scale.Y * 0.5f;
                    bottom = _absolute.Y + _scale.Y * 0.5f;
                }
                else
                {
                    left  = _absolute.X - _scale.X * 0.5f;
                    right = _absolute.X + ((_count - 1) * _spread) + _scale.X * 0.5f;

                    top    = _absolute.Y - _scale.Y * 0.5f;
                    bottom = _absolute.Y + _scale.Y * 0.5f;
                }

                if (coords.X >= left && coords.X <= right && coords.Y >= top && coords.Y <= bottom)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 14
0
 internal void SetTextureSkyboxInternal(string filename, float red = 1, float green = 1, float blue = 1, float intensity = 1, bool isFile = true)
 {
     if (filename == null || filename.Length < 1)
     {
         _textureSkybox = -1;
     }
     else
     {
         if (KWEngine.CustomTextures[this].ContainsKey(filename))
         {
             _textureSkybox = KWEngine.CustomTextures[this][filename];
         }
         else
         {
             _textureSkybox = HelperTexture.LoadTextureSkybox(filename, !isFile);
         }
         _textureBackgroundTint.X = HelperGL.Clamp(red, 0, 1);
         _textureBackgroundTint.Y = HelperGL.Clamp(green, 0, 1);
         _textureBackgroundTint.Z = HelperGL.Clamp(blue, 0, 1);
         _textureBackgroundTint.W = HelperGL.Clamp(intensity, 0, 1);
         _textureBackground       = -1;
     }
 }
Exemplo n.º 15
0
        internal void Draw(Explosion e, ref Matrix4 viewProjection)
        {
            if (e == null || e._model == null || e._currentWorld == null)
            {
                return;
            }

            GL.UseProgram(mProgramId);

            lock (e)
            {
                int type = (int)e._type;

                GL.Uniform4(mUniform_Glow, e.Glow.X, e.Glow.Y, e.Glow.Z, e.Glow.W);
                GL.Uniform1(mUniform_SunAmbient, HelperGL.Clamp(e._currentWorld.SunAmbientFactor * 2f, 0, 1));
                GL.Uniform1(mUniform_Number, (float)e._amount);
                GL.Uniform1(mUniform_Spread, e._spread);
                GL.Uniform3(mUniform_Position, e.Position);
                GL.Uniform1(mUniform_Time, e._secondsAlive / e._duration);
                GL.Uniform1(mUniform_Size, e._particleSize);
                GL.Uniform1(mUniform_Algorithm, e._algorithm);
                GL.Uniform3(mUniform_TintColor, e.Color);
                if (type < 100)
                {
                    GL.Uniform1(mUniform_Towards, 0);
                }
                else if (type >= 100 && type < 1000)
                {
                    GL.Uniform1(mUniform_Towards, 1);
                }
                else
                {
                    GL.Uniform1(mUniform_Towards, 2);
                }
                GL.Uniform4(mUniform_Axes, e._amount, e._directions);
                GL.UniformMatrix4(mUniform_VP, false, ref viewProjection);
                GL.Uniform2(mUniform_TextureTransform, e._textureTransform.X, e._textureTransform.Y);

                if (e._textureId > 0)
                {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.BindTexture(TextureTarget.Texture2D, e._textureId);
                    GL.Uniform1(mUniform_Texture, 0);
                    GL.Uniform1(mUniform_TextureUse, 1);
                }
                else
                {
                    GL.Uniform1(mUniform_TextureUse, 0);
                }

                GeoMesh mesh = e._model.Meshes.ElementAt(0).Value;
                GL.BindVertexArray(mesh.VAO);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                GL.DrawElementsInstanced(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, IntPtr.Zero, e._amount);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

                GL.BindVertexArray(0);
            }

            GL.UseProgram(0);
        }