示例#1
0
        public Camera(Scene scene, string name, string src)
            : base(scene, name, src)
        {
            pos = new Vector3();
            target = new Vector3();
            up = new Vector3(0.0f, 1.0f, 0.0f);
            proj = new Matrix4();
            view = Matrix4.Identity;

            try
            {
                XmlDocument cameraXML = new XmlDocument();
                cameraXML.Load(src);

                foreach( XmlAttribute attrib in cameraXML.DocumentElement.Attributes )
                {
                    if( attrib.Name == "ortho")
                        ortho = (attrib.Value == "true");
                    else if( attrib.Name == "fov")
                        fov = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "near")
                        near = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "far")
                        far = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "left")
                        left = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "right")
                        right = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "top")
                        top = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "bottom")
                        bottom = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "static")
                        isStatic = (attrib.Value == "true");
                    else if( attrib.Name == "shadowDistance")
                        shadowDistance = Convert.ToSingle(attrib.Value);
                    else if( attrib.Name == "identityView")
                        identityView = (attrib.Value == "true");
                }

                foreach( XmlNode child in cameraXML.DocumentElement.ChildNodes )
                {
                    if (child.NodeType == XmlNodeType.Element)
                    {
                        if (child.Name == "position")
                        {
                            var posX = Convert.ToSingle(child.Attributes.GetNamedItem("x").Value);
                            var posY = Convert.ToSingle(child.Attributes.GetNamedItem("y").Value);
                            var posZ = Convert.ToSingle(child.Attributes.GetNamedItem("z").Value);
                            pos = new Vector3(posX, posY, posZ);
                        }
                        else if (child.Name == "lookAt")
                        {
                            var lookAtX = Convert.ToSingle(child.Attributes.GetNamedItem("x").Value);
                            var lookAtY = Convert.ToSingle(child.Attributes.GetNamedItem("y").Value);
                            var lookAtZ = Convert.ToSingle(child.Attributes.GetNamedItem("z").Value);
                            target = new Vector3(lookAtX, lookAtY, lookAtZ);
                        }
                        else if (child.Name == "up")
                        {
                            var upX = Convert.ToSingle(child.Attributes.GetNamedItem("x").Value);
                            var upY = Convert.ToSingle(child.Attributes.GetNamedItem("y").Value);
                            var upZ = Convert.ToSingle(child.Attributes.GetNamedItem("z").Value);
                            up = new Vector3(upX, upY, upZ);
                        }
                        else if (child.Name == "shadowLight")
                        {
                            shadowLight = scene.GetLight(child.Attributes.GetNamedItem("name").Value, child.Attributes.GetNamedItem("src").Value);
                        }
                    }
                }
            }
            catch(Exception )
            {
                System.Windows.Forms.MessageBox.Show("Failed to load camera: " + src);
            }

            if( shadowLight != null )
            {
                shadowCamera = true;
                switch( shadowLight.type )
                {
                    case "dir":
                        Vector3 tempVec = Vector3.Multiply(shadowLight.dir, -shadowDistance);
                        pos = target;
                        pos = Vector3.Add(target, tempVec);
                        break;
                    default:
                        break;
                }
            }

            if( isStatic )
                BuildProj(1);
        }
示例#2
0
        public Light GetLight(string name, string src)
        {
            for (var i = 0; i < lights.Count; i++)
            {
                if (lights[i].name == name)
                    return lights[i];
            }

            Light light = new Light(this, name, src);
            lights.Add(light);
            return light;
        }
示例#3
0
 public void AddLight(Light light)
 {
     if( lightCount < maxLights )
     {
         GL.Uniform3(lightDirs[lightCount], light.dir);
         GL.Uniform3(lightCols[lightCount], light.color);
         lightCount++;
     }
 }