Beispiel #1
0
        byte[] GetVertexColorBytes(MeshVertexColorList vertexColors, out Color4f min, out Color4f max)
        {
            float [] minArr = new float[] { float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity };
            float [] maxArr = new float[] { float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity };

            List <float> colors = new List <float>(vertexColors.Count * 4);

            for (int i = 0; i < vertexColors.Count; i++)
            {
                Color4f color = new Color4f(vertexColors[i]);

                colors.AddRange(color.ToFloatArray());

                minArr[0] = Math.Min(minArr[0], color.R);
                minArr[1] = Math.Min(minArr[1], color.G);
                minArr[2] = Math.Min(minArr[2], color.B);
                minArr[3] = Math.Min(minArr[3], color.A);

                maxArr[0] = Math.Max(maxArr[0], color.R);
                maxArr[1] = Math.Max(maxArr[1], color.G);
                maxArr[2] = Math.Max(maxArr[2], color.B);
                maxArr[3] = Math.Max(maxArr[3], color.A);
            }

            min = new Color4f(minArr[0], minArr[1], minArr[2], minArr[3]);
            max = new Color4f(maxArr[0], maxArr[1], maxArr[2], maxArr[3]);

            IEnumerable <byte> bytesEnumerable = colors.SelectMany(value => BitConverter.GetBytes(value));

            return(bytesEnumerable.ToArray());
        }
Beispiel #2
0
 public SimpleFontHandler(Font font, string text, Vector2f position, Color4f color)
 {
     this.font     = font;
     this.position = position;
     this.color    = color;
     this.text     = text;
 }
Beispiel #3
0
        private void DrawGlyph(SDLGlyph SGlyph, float X, float Y, Color4f Color)
        {
            Gl.glTranslatef(X, Y, 0.0f);
            Gl.glColor4f(Color.r, Color.g, Color.b, Color.a);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, SGlyph.GLTexture);
            //Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
            Gl.glCallList(SGlyph.DispList);
            Gl.glTranslatef(-X, -Y, 0.0f);


            if (RenderBoundingBox)                  //Debug
            {
                Gl.glDisable(Gl.GL_TEXTURE_2D);
                Gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                Gl.glBegin(Gl.GL_LINE_STRIP);
                Gl.glVertex3f(X, Y, 0.0f);
                Gl.glVertex3f(X + SGlyph.Width, Y, 0.0f);
                Gl.glVertex3f(X + SGlyph.Width, Y - SGlyph.Height, 0.0f);
                Gl.glVertex3f(X, Y - SGlyph.Height, 0.0f);
                Gl.glVertex3f(X, Y, 0.0f);
                Gl.glEnd();
                Gl.glEnable(Gl.GL_TEXTURE_2D);
                //Gl.glColor4f((float)SrcColor.Color.R / 255.0f, (float)SrcColor.Color.G / 255.0f, (float)SrcColor.Color.B / 255.0f, (float)SrcColor.Color.A / 255.0f);
            }
        }
Beispiel #4
0
        public static Vec4ub ToVec4ub(this Color4f color)
        {
            ColorSetter4b setter = new ColorSetter4b();

            color.GetColor(setter);
            return(new Vec4ub(setter.C1, setter.C2, setter.C3, setter.C4));
        }
        public void Render(Texture2D tex, Transform transform, float x, float y, float width, float height, Color4f color)
        {
            Setup();
            currentColor = color;
            geom.Material.SetValue(Material.TEXTURE_DIFFUSE, tex);
            geom.Material.SetValue(Material.MATERIAL_BLENDMODE, 1);

            widthScale  = 1f / (game.InputManager.SCREEN_WIDTH);
            heightScale = 1f / (game.InputManager.SCREEN_HEIGHT);
            cscale.Set(width * widthScale, height * heightScale, 1.0f);
            ctrans.x = (2f * ((x * widthScale) + (cscale.x / 2)) - 1f);
            ctrans.y = (2f * ((y * heightScale) + (cscale.y / 2)) - 1f);
            ctrans.z = 1;

            crot = transform.GetRotation();


            RenderManager.Renderer.SetDepthTest(false);
            RenderManager.Renderer.SetDepthMask(false);
            RenderManager.Renderer.SetBlend(true);
            RenderManager.Renderer.SetBlendMode(Renderer.BlendMode.AlphaBlend);

            geom.Render(null, camera);

            RenderManager.Renderer.SetDepthTest(true);
            RenderManager.Renderer.SetDepthMask(true);
            RenderManager.Renderer.SetBlend(false);
        }
Beispiel #6
0
 public Color4b(Color4f c)
 {
     R = (byte)Math.Clamp(c.R * 255.0, 0.0, 255.0);
     G = (byte)Math.Clamp(c.G * 255.0, 0.0, 255.0);
     B = (byte)Math.Clamp(c.B * 255.0, 0.0, 255.0);
     A = (byte)Math.Clamp(c.A * 255.0, 0.0, 255.0);
 }
        public InstantExplosionWeapon(string defaultPath, Camera camera)
        {
            if (sound == null)
                sound = new Sound(defaultPath + "Audio/laserfire3.wav");

            this.reloadTime = 1000;
            this.damage = 10;

            Texture t = new BasicTexture(defaultPath + "Texture/Particle/p.png");
            this.position = new Vector3f();
            this.direction = new Vector3f();
            pe = new PointEmitter(position);

            Vector3f maxV = new Vector3f(10.0f, 10.0f, 10.0f);
            Vector3f minV = maxV * -1.0f;
            Vector3f g = new Vector3f(0.0f, -0.001f, 0.0f);

            Color4f minC = new Color4f(1.0f, 0.7f, 0.7f, 0.0f);
            Color4f maxC = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

            pf = new BillboardedParticleFactory(t, minV, maxV, g, 0.0f, 1.0f, minC, maxC, 0.2f);
            ps = new ParticleSystem(pe, pf, camera, false, 0.1f, 1000);
            pe.setActive(false);
            ps.reset();
        }
Beispiel #8
0
        public void update(float frameTime, List<CollisionSurface> listCollisionSurfaces, List<Manipulator> listManipulators)
        {
            Vector3f positionTemp = position.copy();
            velocity.add(gravity);
            positionTemp.add(velocity * frameTime);
            remainingLife -= frameTime;

            foreach (CollisionSurface cs in listCollisionSurfaces)
            {
                if (cs.getActive() && cs.collisionDetect(position, positionTemp))
                {
                    velocity = cs.computeTrajectory(velocity);
                    positionTemp = position.copy();
                    positionTemp.add(velocity * frameTime);
                }
            }

            foreach (Manipulator m in listManipulators)
            {
                if (m.getActive())
                {
                    Vector3f deltaVelocity = new Vector3f(0.0f, 0.0f, 0.0f);
                    Color4f deltaColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
                    float deltaLife = 0.0f;
                    m.manipulate(this, deltaVelocity, deltaColor, ref deltaLife);
                    velocity.add(deltaVelocity.stretch(frameTime));
                    color.add(deltaColor.multiply(frameTime));
                    remainingLife += deltaLife * frameTime;
                }
            }

            position.set(positionTemp);
        }
Beispiel #9
0
        public void update(float frameTime, List <CollisionSurface> listCollisionSurfaces, List <Manipulator> listManipulators)
        {
            Vector3f positionTemp = position.copy();

            velocity.add(gravity);
            positionTemp.add(velocity * frameTime);
            remainingLife -= frameTime;

            foreach (CollisionSurface cs in listCollisionSurfaces)
            {
                if (cs.getActive() && cs.collisionDetect(position, positionTemp))
                {
                    velocity     = cs.computeTrajectory(velocity);
                    positionTemp = position.copy();
                    positionTemp.add(velocity * frameTime);
                }
            }

            foreach (Manipulator m in listManipulators)
            {
                if (m.getActive())
                {
                    Vector3f deltaVelocity = new Vector3f(0.0f, 0.0f, 0.0f);
                    Color4f  deltaColor    = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
                    float    deltaLife     = 0.0f;
                    m.manipulate(this, deltaVelocity, deltaColor, ref deltaLife);
                    velocity.add(deltaVelocity.stretch(frameTime));
                    color.add(deltaColor.multiply(frameTime));
                    remainingLife += deltaLife * frameTime;
                }
            }

            position.set(positionTemp);
        }
Beispiel #10
0
        private void generateLight(Vector3f lightPos, Color4f dL)
        {
            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < depth; z++)
                {
                    Vector3f L = lightPos.diff(vertrices[x + z * width].position);
                    L.Normalize();
                    float ip = L * vertrices[x + z * width].position;                  //L.multiply(listNormals[i, j].posA);
                    if (ip < 0)
                    {
                        ip = 0;
                    }

                    Color4f vc = new Color4f(0.5f, 1.0f, 1.0f, 1.0f);
                    if (vertrices[x + z * width].color == null)
                    {
                        vertrices[x + z * width].color = new Color4f(0.5f, 1.0f, 1.0f, 1.0f);
                    }

                    Color4f dv = vertrices[x + z * width].color;

                    vc.r = ip * dL.r * dv.r;
                    vc.g = ip * dL.g * dv.g;
                    vc.b = ip * dL.b * dv.b;

                    vertrices[x + z * width].color = vc;
                }
            }
        }
        int?GetMaterial(RenderMaterial material, RhinoObject rhinoObject)
        {
            if (!options.ExportMaterials)
            {
                return(null);
            }

            if (material == null && options.UseDisplayColorForUnsetMaterials)
            {
                Color4f objectColor = GetObjectColor(rhinoObject);
                return(CreateSolidColorMaterial(objectColor));
            }
            else if (material == null)
            {
                material = Rhino.DocObjects.Material.DefaultMaterial.RenderMaterial;
            }

            Guid materialId = material.Id;

            if (!materialsMap.TryGetValue(materialId, out int materialIndex))
            {
                RhinoMaterialGltfConverter materialConverter = new RhinoMaterialGltfConverter(options, binary, dummy, binaryBuffer, material, workflow);
                materialIndex = materialConverter.AddMaterial();
                materialsMap.Add(materialId, materialIndex);
            }

            return(materialIndex);
        }
Beispiel #12
0
        Class1()
        {
            var str  = "Hello World!";
            var mesh = new Point3d(0.0, 0.0, 0.0);

            Color4f.FromArgb(0.0f, 0.0f, 0.0f, 0.0f);
        }
Beispiel #13
0
        public void Draw(string Text, Vector2f position, Color4f Color)
        {
            Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
            char[] TextCharArray = Text.ToCharArray();

            int           LastIndex     = 0;
            List <char[]> SubTextArrays = new List <char[]>();

            for (int i = 0; i < TextCharArray.Length; i++)
            {
                if (TextCharArray[i] == '\n')
                {
                    SubTextArrays.Add(Text.Substring(LastIndex, i - LastIndex).ToCharArray());
                    LastIndex = i + 1;
                }
            }
            SubTextArrays.Add(Text.Substring(LastIndex, Text.Length - LastIndex).ToCharArray());

            for (int i = 0; i < SubTextArrays.Count; i++)
            {
                DrawCharArray(SubTextArrays[i], position.x, position.y - (this.FontSize * i), Color);
            }

            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
        }
Beispiel #14
0
 public SimpleFontHandler(Font font, string text, Vector2f position, Color4f color)
 {
     this.font = font;
     this.position = position;
     this.color = color;
     this.text = text;
 }
Beispiel #15
0
        public FlakedCarPaintMaterial()
        {
            var flake1 = new Color4f(0.002f, 0.502f, 0.002f, 1.0f);

            FlakeColor1 = flake1;
            var shine1 = new Color4f(0.0f, 0.048f, 0.5f, 1.0f);

            CoatColor1 = shine1;
            var flake2 = new Color4f(0.098f, 0.503f, 0.102f, 1.0f);

            FlakeColor2 = flake2;
            var shine2 = new Color4f(0.503f, 0.0f, 0.001f, 1.0f);

            CoatColor2 = shine2;
            FlakeSize  = 100.0f;
            Fresnel    = 1.56f;
            MixFactor  = 0.5f;
            Fields.Add("flake1", flake1, "Flake Color 1");
            Fields.Add("shine1", shine1, "Coat Shine 1");
            Fields.Add("flake2", flake2, "Flake Color 2");
            Fields.Add("shine2", shine2, "Coat Shine 2");
            Fields.Add("flakesize", FlakeSize, "Flake Size");
            Fields.Add("fresnel", Fresnel, "Fresnel");
            Fields.Add("gamma", MixFactor, "Flake and Shine Mix Factor");
        }
        public InstantExplosionWeapon(string defaultPath, Camera camera)
        {
            if (sound == null)
            {
                sound = new Sound(defaultPath + "Audio/laserfire3.wav");
            }

            this.reloadTime = 1000;
            this.damage     = 10;

            Texture t = new BasicTexture(defaultPath + "Texture/Particle/p.png");

            this.position  = new Vector3f();
            this.direction = new Vector3f();
            pe             = new PointEmitter(position);

            Vector3f maxV = new Vector3f(10.0f, 10.0f, 10.0f);
            Vector3f minV = maxV * -1.0f;
            Vector3f g    = new Vector3f(0.0f, -0.001f, 0.0f);

            Color4f minC = new Color4f(1.0f, 0.7f, 0.7f, 0.0f);
            Color4f maxC = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

            pf = new BillboardedParticleFactory(t, minV, maxV, g, 0.0f, 1.0f, minC, maxC, 0.2f);
            ps = new ParticleSystem(pe, pf, camera, false, 0.1f, 1000);
            pe.setActive(false);
            ps.reset();
        }
Beispiel #17
0
 public Particle(Vector3f position, Vector3f velocity, Vector3f gravity, Color4f color, float life, float size)
 {
     this.position = position;
     this.velocity = velocity;
     this.gravity  = gravity;
     this.color    = color;
     startLife = remainingLife = life;
     this.size = size;
 }
    public void AddLine(Point3d from, Point3d to, Color4f color)
    {
        m_start_pts.Add(from);
        m_end_pts.Add(to);
        m_colors.Add(color);

        m_bounding_box.Union(from);
        m_bounding_box.Union(to);
    }
Beispiel #19
0
 public Cube(Color4f color, Vector3f pos, float width, float height, float depth)
 {
     this.pos    = pos;
     this.color  = color;
     this.width  = width;
     this.height = height;
     this.depth  = depth;
     rot         = 0.0f;
 }
Beispiel #20
0
 public Light(Vector3f position, Color4f color, float start, float end, CalculationMode lightCalculation)
 {
     this.position         = position;
     this.color            = color;
     this.start            = start;
     this.end              = end;
     this.len              = end - start;
     this.lightCalculation = lightCalculation;
 }
Beispiel #21
0
        public void BakeParameters()
        {
            Color4f col;

            if (Fields.TryGetValue("diffuse_color", out col))
            {
                Diffuse = col;
            }
        }
Beispiel #22
0
 public Particle(Vector3f position, Vector3f velocity, Vector3f gravity, Color4f color, float life, float size)
 {
     this.position = position;
     this.velocity = velocity;
     this.gravity  = gravity;
     this.color    = color;
     startLife     = remainingLife = life;
     this.size     = size;
 }
Beispiel #23
0
 public Light(Vector3f position, Color4f color, float start, float end, CalculationMode lightCalculation)
 {
     this.position = position;
     this.color    = color;
     this.start    = start;
     this.end      = end;
     this.len      = end - start;
     this.lightCalculation = lightCalculation;
 }
Beispiel #24
0
 public Cube(Color4f color, Vector3f pos, float width, float height, float depth)
 {
     this.pos = pos;
     this.color = color;
     this.width = width;
     this.height = height;
     this.depth = depth;
     rot = 0.0f;
 }
Beispiel #25
0
        public void SetColor(int x, int y, Color4f c)
        {
            int start = (y * Width + x) * 4;

            data[start].Color     = c;
            data[start + 1].Color = c;
            data[start + 2].Color = c;
            data[start + 3].Color = c;
            changed = true;
        }
Beispiel #26
0
        public TexturedCube(Texture texture, Vector3f pos, float width, float height, float depth)
        {
            this.pos = pos;
            this.width = width;
            this.height = height;
            this.depth = depth;
            this.texture = texture;

            rotation = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
        }
Beispiel #27
0
        public TexturedCube(Texture texture, Vector3f pos, float width, float height, float depth)
        {
            this.pos     = pos;
            this.width   = width;
            this.height  = height;
            this.depth   = depth;
            this.texture = texture;

            rotation = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
        }
        void HandleBaseColor(Rhino.DocObjects.Material rhinoMaterial, glTFLoader.Schema.Material gltfMaterial)
        {
            Rhino.DocObjects.Texture baseColorDoc    = rhinoMaterial.GetTexture(TextureType.PBR_BaseColor);
            Rhino.DocObjects.Texture alphaTextureDoc = rhinoMaterial.GetTexture(TextureType.PBR_Alpha);

            RenderTexture baseColorTexture = rhinoMaterial.RenderMaterial.GetTextureFromUsage(RenderMaterial.StandardChildSlots.PbrBaseColor);
            RenderTexture alphaTexture     = rhinoMaterial.RenderMaterial.GetTextureFromUsage(RenderMaterial.StandardChildSlots.PbrAlpha);

            bool baseColorLinear = baseColorTexture == null ? false : IsLinear(baseColorTexture);

            bool hasBaseColorTexture = baseColorDoc == null ? false : baseColorDoc.Enabled;
            bool hasAlphaTexture     = alphaTextureDoc == null ? false : alphaTextureDoc.Enabled;

            bool baseColorDiffuseAlphaForTransparency = rhinoMaterial.PhysicallyBased.UseBaseColorTextureAlphaForObjectAlphaTransparencyTexture;

            Color4f baseColor = rhinoMaterial.PhysicallyBased.BaseColor;

            if (workflow.PreProcessColors)
            {
                baseColor = Color4f.ApplyGamma(baseColor, workflow.PreProcessGamma);
            }

            if (!hasBaseColorTexture && !hasAlphaTexture)
            {
                gltfMaterial.PbrMetallicRoughness.BaseColorFactor = new float[]
                {
                    baseColor.R,
                    baseColor.G,
                    baseColor.B,
                    (float)rhinoMaterial.PhysicallyBased.Alpha,
                };

                if (rhinoMaterial.PhysicallyBased.Alpha == 1.0)
                {
                    gltfMaterial.AlphaMode = glTFLoader.Schema.Material.AlphaModeEnum.OPAQUE;
                }
                else
                {
                    gltfMaterial.AlphaMode = glTFLoader.Schema.Material.AlphaModeEnum.BLEND;
                }
            }
            else
            {
                gltfMaterial.PbrMetallicRoughness.BaseColorTexture = CombineBaseColorAndAlphaTexture(baseColorTexture, alphaTexture, baseColorDiffuseAlphaForTransparency, baseColor, baseColorLinear, (float)rhinoMaterial.PhysicallyBased.Alpha, out bool hasAlpha);

                if (hasAlpha)
                {
                    gltfMaterial.AlphaMode = glTFLoader.Schema.Material.AlphaModeEnum.BLEND;
                }
                else
                {
                    gltfMaterial.AlphaMode = glTFLoader.Schema.Material.AlphaModeEnum.OPAQUE;
                }
            }
        }
Beispiel #29
0
        public MultiTexturedQuad(Texture t0, Texture t1, Texture t2, Vector2f pos)
        {
            this.pos    = pos;
            this.width  = 1.0f;
            this.height = 1.0f;

            this.t0 = t0;
            this.t1 = t1;
            this.t2 = t2;
            c       = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);
        }
Beispiel #30
0
        Bitmap SolidColorImage(Color4f color, Size size)
        {
            Bitmap bmp = new Bitmap(size.Width, size.Height);

            using (Graphics gfx = Graphics.FromImage(bmp))
            {
                gfx.FillRectangle(new SolidBrush(color.AsSystemColor()), 0, 0, size.Width, size.Height);
            }

            return(bmp);
        }
Beispiel #31
0
        private void ButtonColorClick(object sender, System.EventArgs e)
        {
            Color4f color = m_view_model.VariesColor.Value;

            if (!Rhino.UI.Dialogs.ShowColorDialog((object)this, ref color, false))
            {
                return;
            }

            m_view_model.VariesColor = color;
        }
Beispiel #32
0
 public MultiTexturedCube(Texture t0, Texture t1, Texture t2, Vector3f pos)
 {
     this.pos = pos;
     this.width = 1.0f;
     this.height = 1.0f;
     this.depth = 1.0f;
     this.t0 = t0;
     this.t1 = t1;
     this.t2 = t2;
     c = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);
 }
Beispiel #33
0
        public static Color4f Contrast(Color4f color, float contrast)
        {
            var red   = ((color.R - 0.5f) * contrast) + 0.5f;
            var green = ((color.G - 0.5f) * contrast) + 0.5f;
            var blue  = ((color.B - 0.5f) * contrast) + 0.5f;

            red   = Math.Min(1.0f, Math.Max(0.0f, red));
            green = Math.Min(1.0f, Math.Max(0.0f, green));
            blue  = Math.Min(1.0f, Math.Max(0.0f, blue));

            return(Color4f.FromArgb(color.A, red, green, blue));
        }
        Bitmap BitmapForScene(CreatePreviewEventArgs scene, Color4f color)
        {
            var bitmap = new Bitmap(scene.PreviewImageSize.Width, scene.PreviewImageSize.Height, PixelFormat.Format24bppRgb);

            // Fill the bitmap using the computed color
            using (var g = Graphics.FromImage(bitmap))
            {
                g.Clear(Color.FromArgb(255, color.AsSystemColor()));
                g.DrawRectangle(Pens.Black, 0, 0, bitmap.Width - 1, bitmap.Height - 1);
            }
            return(bitmap);
        }
        int CreateSolidColorMaterial(Color4f color)
        {
            glTFLoader.Schema.Material material = new glTFLoader.Schema.Material()
            {
                PbrMetallicRoughness = new MaterialPbrMetallicRoughness()
                {
                    BaseColorFactor = color.ToFloatArray(),
                }
            };

            return(dummy.Materials.AddAndReturnIndex(material));
        }
Beispiel #36
0
        public void Draw(string text, Vector2f position, Color4f color)
        {
            string[] rows = text.Split('\n');

            Gl.glPushMatrix();
            Gl.glColor4f(color.r, color.g, color.b, color.a);
            Gl.glTranslatef(position.x, position.y, 0.0f);
            for (int i = 0; i < rows.Length; i++)
            {
                font.Render(rows[i]);
                Gl.glTranslatef(0.0f, -fontSize, 0.0f);
            }
            Gl.glPopMatrix();
        }
Beispiel #37
0
        int GetVertexColorBuffer(MeshVertexColorList vertexColors, out Color4f min, out Color4f max, out int byteLength)
        {
            byte[] bytes = GetVertexColorBytes(vertexColors, out min, out max);

            glTFLoader.Schema.Buffer vertexColorsBuffer = new glTFLoader.Schema.Buffer()
            {
                Uri        = Constants.TextBufferHeader + Convert.ToBase64String(bytes),
                ByteLength = bytes.Length,
            };

            byteLength = bytes.Length;

            return(dummy.Buffers.AddAndReturnIndex(vertexColorsBuffer));
        }
Beispiel #38
0
        public void Draw(string text, Vector2f position, Color4f color)
        {
            string[] rows = text.Split('\n');

            Gl.glPushMatrix();
            Gl.glColor4f(color.r, color.g, color.b, color.a);
            Gl.glTranslatef(position.x, position.y, 0.0f);
            for (int i = 0; i < rows.Length; i++)
            {
                font.Render(rows[i]);
                Gl.glTranslatef(0.0f, -fontSize, 0.0f);
            }
            Gl.glPopMatrix();
        }
        public override void AddKeyPoint(float time)
        {
            Color4f v = m_DataSource.GetValueByTime(time);

            m_DataSource.AddKey(v, time);
            ColorKeyPoint kp = new ColorKeyPoint();

            kp.m_Value = v;
            kp.Time    = time;
            m_Value.Add(kp);
            KeyPointComparer kpc = new KeyPointComparer();

            m_Value.Sort(kpc);
        }
        public BillboardedParticleFactory(Texture texture, Vector3f minimalInitialVelocity, Vector3f maximumInitialVelocity,
								  Vector3f gravity, float minimalParticleLife, float maximumParticleLife,
								  Color4f minimalColor, Color4f maximumColor, float size)
        {
            this.texture = texture;
            this.minimalInitialVelocity = minimalInitialVelocity;
            this.maximumInitialVelocity = maximumInitialVelocity;
            this.gravity = gravity;
            this.minimalParticleLife = minimalParticleLife;
            this.maximumParticleLife = maximumParticleLife;
            this.minimalColor = minimalColor;
            this.maximumColor = maximumColor;
            this.size = size;

            random = new Random();
        }
        public Particle createParticle(Vector3f emitterPosition, bool emitterUseDirection, Vector3f emitterDirection)
        {
            Color4f color = new Color4f((maximumColor.a - minimalColor.a) * random.NextDouble() + minimalColor.a,
                                        (maximumColor.r - minimalColor.r) * random.NextDouble() + minimalColor.r,
                                        (maximumColor.g - minimalColor.g) * random.NextDouble() + minimalColor.g,
                                        (maximumColor.b - minimalColor.b) * random.NextDouble() + minimalColor.b);
            Vector3f velocity = new Vector3f((maximumInitialVelocity.x - minimalInitialVelocity.x) * random.NextDouble(),
                                           (maximumInitialVelocity.y - minimalInitialVelocity.y) * random.NextDouble(),
                                           (maximumInitialVelocity.z - minimalInitialVelocity.z) * random.NextDouble());
            velocity.add(minimalInitialVelocity);
            float particleLife = minimalParticleLife;
            float t = (maximumParticleLife - minimalParticleLife);
            particleLife += t * (float)random.NextDouble();

            return new BillboardedParticle(emitterPosition.copy(), velocity, gravity, color, particleLife, size);
        }
Beispiel #42
0
        public override void manipulate(Particle particle, Vector3f deltaVelocity, Color4f deltaColor, ref float deltaLife)
        {
            Vector3f tmp = this.position.diff(particle.position);
            float len2 = tmp.length2();
            if (len2 > size2)
                return;
            else if (len2 < threshold2)
            {
                deltaVelocity.set(particle.velocity);
                deltaVelocity.stretch(strength);
                deltaVelocity.invert();
                return;
            }

            len2 = size2 / len2;

            deltaVelocity.set(tmp);
            deltaVelocity.stretch(strength);
            deltaVelocity.stretch(len2);
        }
Beispiel #43
0
        public ActorInfoWindow()
            : base(0, 0, 64, 24, new Layout(1, 4))
        {
            HitpointBar = new ProgressBar(new Color4f(0.2f, 0.2f, 0.2f, 0.25f), new Color4f(0, 1, 0, 0.8f), OrientationType.Horizontal);
            Add(HitpointBar, 0, 1);

            ShieldBar = new ProgressBar(new Color4f(0.2f, 0.2f, 0.2f, 0.25f), new Color4f(0, 0, 1, 0.8f), OrientationType.Horizontal);
            Add(ShieldBar, 0, 2);

            EneryBar = new ProgressBar(new Color4f(0.2f, 0.2f, 0.2f, 0.25f), new Color4f(1, 1, 0, 0.8f), OrientationType.Horizontal);
            EneryBar.Value = 1;
            Add(EneryBar, 0, 3);

            Name = new Button("");
            Add(Name, 0, 0);

            Color = new Color4f(0, 0, 0, 0);
            Transparent = true;

            Layout.Update(this.Size);
        }
Beispiel #44
0
        public BodyBox(World hostWorld, Space space, Vector3f position, Vector3f size, Vector3f force)
        {
            this.hostWorld = hostWorld;
            this.space = space;

            bodyID = Ode.dBodyCreate(hostWorld.getID());

            // create a mass object, in this case a box of size 50 x 0.2 x 50
            Ode.dMass mass = new Ode.dMass();
            //Ode.dMassSetBox(ref mass, 200.0f, radius, radius, radius);
            Ode.dMassSetBoxTotal(ref mass, 200.0f, size.x, size.y, size.z);
            // set it's mass to 1000.0f. If this value is too low,
            // you'll get some wierd collisions
            //mass.mass = 1000.0f;

            // set the mass object on the body
            Ode.dBodySetMass(bodyID, ref mass);

            // Set the body's position
            Ode.dBodySetPosition(bodyID, position.x, position.y, position.z);

            // Set an initial force on the body. This will be
            // wiped to zero after the first frame.
            Ode.dBodyAddForce( bodyID, force.x, force.y, force.z );

            // create a collion geometry to go with our rigid body.
            // without this, the rigid body will not collide with anything.
            geomID = Ode.dCreateBox(space.getSpaceID(), size.x, size.y, size.z);

            // assign a rigid body to the collision geometry. If we didn't do this,
            // the object would be a static object much like our ground plane.
            Ode.dGeomSetBody(geomID, bodyID);

            this.position = position.copy();
            this.rotationOGL = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
        }
Beispiel #45
0
 public BillboardedParticle(Vector3f position, Vector3f velocity, Vector3f gravity, Color4f color, float life, float size)
     : base(position, velocity, gravity, color, life, size)
 {
 }
Beispiel #46
0
 public Color3f(Color4f other)
     : base(other)
 {
 }
Beispiel #47
0
        public JoinGameMenu()
            : base(100, 400, 420, 300, new Layout(3, 2))
        {
            Color = new Color4f(0.0f, 0.0f, 0.0f, 1.0f);
            Center();
            Add(Host = new TextBox("localhost", false), 0, 0);
            Add(new Button(new Button.ClickDelegate(ConnectButtonClicked), "Connect!"), 1, 0);
            //Add(new Button(new Button.ClickDelegate(BackButtonClicked), "Back"), 2, 0);

            ServerList = new ListBox();
            ServerList.SelectionChangedEvent += new ListBox.SelectionChangedDelegate(ServerList_SelectionChangedEvent);
            Add(ServerList, 0, 1);
            Layout.Widths[0] = 3;
            Layout.Heights[0] = 0.1f;
            Layout.Update(this.Size);
            Layout.GetCell(0, 1).Span.X = 3;

            Scanner = new ServerFinder(OnServerAnswer,true,true);
        }
Beispiel #48
0
        private void SetRow(int row, string name, string frags, string deaths, string rtt, Color4f color)
        {
            ((Button)Layout.GetCell(0, row + 2).Windows[0]).Caption = name;
            ((Button)Layout.GetCell(0, row + 2).Windows[0]).TextColor = color;

            ((Button)Layout.GetCell(1, row + 2).Windows[0]).Caption = frags;
            ((Button)Layout.GetCell(1, row + 2).Windows[0]).TextColor = color;

            ((Button)Layout.GetCell(2, row + 2).Windows[0]).Caption = deaths;
            ((Button)Layout.GetCell(2, row + 2).Windows[0]).TextColor = color;

            ((Button)Layout.GetCell(3, row + 2).Windows[0]).Caption = rtt;
            ((Button)Layout.GetCell(3, row + 2).Windows[0]).TextColor = color;
        }
Beispiel #49
0
        public MainMenu()
            : base(0, 0, Root.Instance.UserInterface.Renderer.Size.X, Root.Instance.UserInterface.Renderer.Size.Y, new Layout(6, 4))
        {
            Color = new Color4f(0, 0, 0, 0);

            float resy = Size.Y;
            float resx = Size.X;
            float want = 50;
            Layout.Heights[0] = want;
            Layout.Heights[3] = want;
            Layout.Heights[1] = Layout.Heights[2] = (resy - 2 * want) / 2;
            Layout.Widths[0] = Layout.Widths[1] = Layout.Widths[2] = Layout.Widths[4] = Layout.Widths[5] = 75;
            Layout.Widths[3] = resx - 5 * 75;

            Window w = new Window();
            w.Shader = Root.Instance.ResourceManager.LoadShader("window.textured.shader");
            w.texture = Root.Instance.ResourceManager.LoadTexture("main2.avi");
            w.Color = new Color4f(1, 1, 1, 1);
            Layout.GetCell(0, 1).Span.X = 6;
            Layout.GetCell(0, 1).Span.Y = 2;
            Add(w, 0, 1);

            w = new Window();
            w.Shader = Root.Instance.ResourceManager.LoadShader("window.gradiant.shader");
            w.ShaderParams = new ShaderParams();
            w.ShaderParams[w.Shader.GetUniformLocation("Gradiant")] = new float[] { 0, -1, 1, 1 };
            w.Color = new Color4f(1, 1, 1, 1);
            Layout.GetCell(5, 1).Span.X = -6;
            //Layout.GetCell(4, 1).Span.Y = 2;
            Add(w, 5, 1);

            w = new Window();
            w.Shader = Root.Instance.ResourceManager.LoadShader("window.gradiant.shader");
            w.ShaderParams = new ShaderParams();
            w.ShaderParams[w.Shader.GetUniformLocation("Gradiant")] = new float[] { 0, 1, 1, 0 };
            w.Color = new Color4f(1, 1, 1, 1);
            Layout.GetCell(5, 2).Span.X = -6;
            Add(w, 5, 2);

            Button b = new Button(OnJoinButtonPressed, "Multiplayer");
            b.Color = b.NormalColor = new Color4f(0, 1, 0, 1);
            b.FocusColor = new Color4f(0.5f, 1, 0.5f, 1);
            b.Tooltip = OnTooltip;
            b.TooltipText = "Join LAN/Internet game.";
            //Root.Instance.Gui.windows.Add(b);
            Add(b, 0, 3);

            b = new Button(OnReplayButtonPressed, "Replay");
            b.Color = b.NormalColor = new Color4f(0, 0, 1, 1);
            b.FocusColor = new Color4f(0.5f, 0.5f, 1, 1);
            b.Tooltip = OnTooltip;
            b.TooltipText = "Play a demo.";
            Add(b, 1, 3);

            b = new Button(OnSingleButtonPressed, "Singleplayer");
            b.Color = b.NormalColor = new Color4f(0, 1, 1, 1);
            b.FocusColor = new Color4f(0.5f, 1, 1, 1);
            b.Tooltip = OnTooltip;
            b.TooltipText = "Play vs. Bots.";
            Add(b, 2, 3);

            b = new Button(OnConfigButtonPressed, "Config");
            b.Color = b.NormalColor = new Color4f(1, 1, 0, 1);
            b.FocusColor = new Color4f(1, 1, 0.5f, 1);
            b.Tooltip = OnTooltip;
            b.TooltipText = "Configure player settings and controls.";
            Add(b, 4, 3);

            //MeshWindow mw = new MeshWindow(Root.Instance.ResourceManager.LoadMesh("quad/quad.mesh"));
            //Add(mw, 4, 3);

            b = new Button(OnExitButtonPressed, "Exit");
            b.Color = b.NormalColor = new Color4f(1, 0, 0, 1);
            b.FocusColor = new Color4f(1, 0.5f, 0.5f, 1);
            b.Tooltip = OnTooltip;
            b.TooltipText = "Quit playing.   <°)))><";
            Add(b, 5, 3);

            TooltipButton = b = new Button(null, "Welcome to SpaceWar 2006[tm]!");
            b.Color = b.NormalColor = b.FocusColor = new Color4f(0, 0, 0, 0);
            Add(b, 3, 3);

            Layout.Update(Size);
        }
Beispiel #50
0
 public void On(Computer c)
 {
     on = Visible = true;
     comp = c;
     Color = new Color4f(0.0f, 1.0f, 0.0f, 0.2f);
 }
Beispiel #51
0
        private void Update()
        {
            if (!Visible)
                return;

            IList<Player> plist = Root.Instance.Scene.FindEntitiesByType<Player>();
            Player[] Players = new Player[plist.Count];
            plist.CopyTo(Players, 0);
            //p.
            GameRule Rule = Root.Instance.Scene.FindEntityByType<GameRule>();

            if (Rule != null)
                Title.Caption = Rule.ToString();
            else
                Title.Caption = "SpaceWar 2006";

            //#if WINDOWS
            Array.Sort<Player>(Players, new Comparison<Player>(delegate(Player e1, Player e2)
            {
                int i1 = ((Player)e1).Team;
                int i2 = ((Player)e2).Team;

                if (i1 < i2) return -1;
                if (i1 > i2) return 1;

                int f1 = ((Player)e1).Frags;
                int f2 = ((Player)e2).Frags;

                if (f1 > f2) return -1;
                if (f1 < f2) return 1;

                return 0;
            }));
            //#endif

            int i = 0;

            if (Rule != null && Rule is TeamDeathMatch)
            {
                TeamDeathMatch tdm = (TeamDeathMatch)Rule;
                int currentteam = -1;
                //foreach (Player p in Players)
                for (int j = 0; j < Players.Length; ++j)
                {
                    Player p = Players[j];
                    Color4f c = new Color4f(1, 1, 1, 1);
                    if (p.Team >= 0)
                        c = Team.Colors[p.Team];

                    if (p.Team != currentteam)
                    {
                        currentteam = p.Team;
                        SetTeamRow(i++, p.Team, tdm.Teams[p.Team].Name, (Rule is CaptureTheFlag) ? ((CtfTeam)tdm.Teams[p.Team]).Captures : tdm.Teams[p.Team].Score, c);
                    }

                    SetRow(i++, p.Name, p.Frags.ToString(), p.Deaths.ToString(), p.RTT.ToString(), c);
                }
            }
            else if (Rule != null && Rule is Domination)
            {
                Domination dom = (Domination)Rule;
                int currentteam = -1;
                //foreach (Player p in Players)
                for (int j = 0; j < Players.Length; ++j)
                {
                    Player p = Players[j];
                    Color4f c = new Color4f(1, 1, 1, 1);
                    if (p.Team >= 0)
                        c = Team.Colors[p.Team];

                    if (p.Team != currentteam)
                    {
                        currentteam = p.Team;
                        SetTeamRow(i++, p.Team, dom.Teams[p.Team].Name, dom.Teams[p.Team].Score, c);
                    }

                    SetRow(i++, p.Name, p.Frags.ToString(), p.Deaths.ToString(), p.RTT.ToString(), c);
                }
            }
            else if (Rule != null && Rule is Race)
            {
                Race race = (Race)Rule;

                for (int j = 0; j < Players.Length; ++j)
                {
                    RacePlayer p = (RacePlayer)Players[j];
                    SetRow(i++, p.Name, p.Frags.ToString(), p.Checks.ToString(), p.RTT.ToString(), new Color4f(1, 1, 1, 1));
                }
            }
            else if (Rule != null && Rule is Mission)
            {
                Mission m = (Mission)Rule;

                for (int j = 0; j < m.Missions.Length; ++j)
                {
                    SingleMission sm = m.Missions[j];
                    SetTeamRow(i++, j, m.Teams[j].Name, m.Teams[j].Score, Team.Colors[j]);

                    for (int k = 0; k < sm.PrimaryObjectives.Length; ++k)
                    {
                        Objective o = sm.PrimaryObjectives[k];
                        SetRow(i++, o.Text, "", o.CurrentStatus.ToString(), "", new Color4f(1,1,1,1));
                    }
                }
            }
            else
            {
                //foreach (Player p in Players)
                for (int j = 0; j < Players.Length; ++j)
                {
                    Player p = Players[j];
                    SetRow(i++, p.Name, p.Frags.ToString(), p.Deaths.ToString(), p.RTT.ToString(), new Color4f(1, 1, 1, 1));
                }
            }

            for (; i < 16; ++i)
                SetEmptyRow(i);
        }
Beispiel #52
0
 public void SetColor(int x, int y, Color4f c)
 {
     int start=(y*Width+x)*4;
     data[start].Color = c;
     data[start+1].Color = c;
     data[start+2].Color = c;
     data[start+3].Color = c;
     changed = true;
 }
Beispiel #53
0
 public void setRotation(Color4f rotation)
 {
     this.rotation = rotation;
 }
Beispiel #54
0
        private void generateLight(Vector3f lightPos, Color4f dL)
        {
            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < depth; z++)
                {
                    Vector3f L = lightPos.diff(vertrices[x + z*width].position);
                    L.Normalize();
                    float ip = L * vertrices[x + z*width].position;//L.multiply(listNormals[i, j].posA);
                    if (ip < 0)
                        ip = 0;

                    Color4f vc = new Color4f(0.5f, 1.0f, 1.0f, 1.0f);
                    if (vertrices[x + z*width].color == null)
                        vertrices[x + z*width].color = new Color4f(0.5f, 1.0f, 1.0f, 1.0f);

                    Color4f dv = vertrices[x + z*width].color;

                    vc.r = ip * dL.r * dv.r;
                    vc.g = ip * dL.g * dv.g;
                    vc.b = ip * dL.b * dv.b;

                    vertrices[x + z*width].color = vc;
                }
            }
        }
Beispiel #55
0
 public void set(Color4f argColor)
 {
     x = argColor.x;
     y = argColor.y;
     z = argColor.z;
     w = argColor.w;
 }
Beispiel #56
0
 private void SetTeamRow(int row, int team, string name, int score, Color4f color)
 {
     SetRow(row, "Team:", "\"" + name + "\"", "Score:", score.ToString(), color);
 }
Beispiel #57
0
        public Grid(float size, int width, int height)
        {
            Size = size;
            Width = width;
            Height = height;

            if (Root.Instance.UserInterface == null)
                return;

            fieldcount = width * height;
            vertexcount = fieldcount * 4;
            data = new VertexP3C4[vertexcount];
            int i = 0;
            material = Material.CreateSimpleMaterial(null);
            material.DepthTest = true;
            material.DepthWrite = true;
            material.Additive = true;

            //float cy = 1.0f / (float)height * size;
            //float cy = 1.0f / (float)width * size;
            indices = new IndexBuffer();
            indices.buffer = new int[fieldcount * 6];

            for (int y = 0; y < height; ++y)
            {
                float yp = (float)y * size -(size * height / 2);
                for (int x = 0; x < width; ++x)
                {
                    float xp = (float)x * size -(size * width / 2);
                    Color4f color = new Color4f(VecRandom.Instance.NextFloat(), VecRandom.Instance.NextFloat(), VecRandom.Instance.NextFloat(),1);

                    data[i].Color = color;
                    data[i].Position = new Vector3(xp, 0, yp);
                    data[i + 1].Color = color;
                    data[i + 1].Position = new Vector3(xp + size, 0, yp);

                    data[i + 2].Color = color;
                    data[i + 2].Position = new Vector3(xp, 0, yp + size);
                    data[i + 3].Color = color;
                    data[i + 3].Position = new Vector3(xp+size, 0, yp+size);

                    int idx = i / 4 * 6;
                    indices.buffer[idx] = i;
                    indices.buffer[idx+1] = i+1;
                    indices.buffer[idx+2] = i+2;
                    indices.buffer[idx+3] = i+1;
                    indices.buffer[idx+4] = i+3;
                    indices.buffer[idx+5] = i+2;

                    i += 4;
                }
            }
            buffersize=vertexcount * (3+4) * 4;
            vertices = Root.Instance.UserInterface.Renderer.CreateDynamicVertexBuffer(buffersize);
            vertices.Format = VertexFormat.VF_P3C4;
            vertices.Update(data, buffersize);

            shader = Root.Instance.ResourceManager.LoadShader("simple3d.shader");
        }
Beispiel #58
0
        void UpdateBuffer()
        {
            if (Root.Instance.UserInterface == null)
                return;

            IList<Node> list = Root.Instance.Scene.FindEntitiesByType<Node>();

            Vector3 offset = new Vector3(5000, 0, 5000);
            Vector3 scale = new Vector3(Size.X / 10000.0f, Size.Y / 10000.0f, 0);

            int i = 0;
            foreach (Node n in list)
            {
                Color4f c;
                float a = 0.7f;
                float pointsize = 1;
                if (n is SpaceShip)
                {
                    c = new Color4f(1, 1, 0, a);
                    pointsize = 5;
                }
                else if (n is Projectile)
                    c = new Color4f(1, 0, 0, a);
                else if (n is Planet)
                {
                    pointsize = 7;
                    c = new Color4f(0, 0, 1, a);
                }
                else if (n is Actor)
                {
                    c = new Color4f(1, 1, 1, a);
                    pointsize = 3;
                }
                else if (n is BigExplosion)
                {
                    c = new Color4f(1, 1, 1, a);
                    pointsize = 11;
                }
                else if (n is SpawnPoint || n is PlayerStart)
                {
                    c = new Color4f(0, 1, 1, a);
                    pointsize = 11;
                }
                else if (n is Flag)
                {
                    c = new Color4f(0.5f, 1, 0, a);
                    pointsize = 11;
                }
                else
                    continue;

                Vector3 v = n.AbsolutePosition + offset;
                v = new Vector3(v.X * scale.X, v.Z * scale.Y, 0);
                //v.X += Position.x;
                //v.Y += Position.y;
                Vertices[i].position = v;
                Vertices[i].texture0.X = pointsize;
                c.a = pointsize;

                Vertices[i++].color = c;
            }
            Count = i;

            PointBuffer.Update(Vertices, Count * 36);
        }
Beispiel #59
0
 public override void manipulate(Particle particle, Vector3f deltaVelocity, Color4f deltaColor, ref float deltaLife)
 {
     deltaVelocity.set(particle.velocity);
     deltaVelocity.stretch(strength);
     deltaVelocity.invert();
 }
Beispiel #60
0
        public override void SetRenderParameters(IRenderer r, IDrawable draw, Shader shade)
        {
            base.SetRenderParameters(r, draw, shade);

            int loc = shade.GetUniformLocation("Color");
            if (loc >= 0)
            {
                float f = 1.0f;
                Color4f c = new Color4f(f, f, f, 0.5f);
                if (Team >= 0)
                    c = SpaceWar2006.GameObjects.Team.Colors[Team];
                r.SetUniform(loc, new float[] { c.r * f, c.g * f, c.b * f, 0.5f });
            }
            else throw new Exception();
        }