コード例 #1
0
        public override Scene MakeScene()
        {
            Scene       scene   = new Scene();
            Shape       shape   = new Shape();
            Appearance  app     = new Appearance();
            TriMesh     mesh    = new TriMesh(VertexPool.TEXCOORDS);
            MediaSource video   = new MediaSource();
            SoundPlayer sound   = null;
            Texture     tex     = new Texture();
            Sampler     sampler = new Sampler();
            Camera      cam;
            Vec2        videosize = new Vec2(1, 1);          // pixel dimensions of video frame
            Vec2        texsize   = new Vec2(512, 512);      // pixel dimensions of texture (powers of 2)

            video.Name     = "videotest.simroot";
            video.Control  = Engine.CYCLE;
            video.Target   = tex;
            video.FileName = GetMediaPath(ContentFile);
            videosize      = video.VideoSize;
            if (videosize.x > 0)
            {
                texsize = video.TexSize;
            }
            if (AudioFile != "")
            {
                sound          = new SoundPlayer();
                sound.FileName = GetMediaPath(AudioFile);
                video.Append(sound);
            }
            tex.Name = "videotest.videotexture";
            sampler.Set(Sampler.TEXTUREOP, Sampler.EMISSION);
            sampler.Set(Sampler.TEXCOORD, 0);
            sampler.Set(Sampler.MIPMAP, 0);
            sampler.Texture = tex;
            app.Set(Appearance.CULLING, 0);
            app.Set(Appearance.LIGHTING, 0);
            app.SetSampler(0, sampler);
            shape.Appearance = app;
            GeoUtil.Rect(mesh, videosize.x / videosize.y, 1.0f, videosize.x / texsize.x, videosize.y / texsize.y);
            shape.Geometry  = mesh;
            shape.Name      = "videotest.root";
            scene.Models    = shape;
            scene.Engines   = video;
            cam             = scene.Camera;
            cam.Translation = new Vec3(0.0f, 0.0f, 2.0f);
            cam.Hither      = 0.1f;
            cam.Name        = "videotest.camera";
            return(scene);
        }
コード例 #2
0
        /*
         * Make the shape for the Kinect depth camera output
         */
        protected Shape MakeCameraOutputShape(Camera cam, bool iscolor)
        {
            Shape         shape     = new Shape();
            Appearance    app       = new Appearance();
            PhongMaterial mtl       = new PhongMaterial(new Col4(1.0f, 1.0f, 1.0f, 0.7f));
            Sampler       sampler   = new Sampler();
            TriMesh       mesh      = new TriMesh("position float 3, normal float 3, texcoord float 2");
            Vec2          videosize = new Vec2(640, 480);
            Vec2          texsize   = new Vec2(1024, 512);
            Box3          vvol      = cam.ViewVol;
            Vec3          campos    = cam.Translation;
            float         camdist   = campos.Length;            // distance of camera from body
            float         backdist  = camdist + vvol.max.z / 6.0f;
            float         h         = backdist * vvol.Height / vvol.min.z;
            float         w         = h;

            backdist -= camdist;
            if (Kinect != null)
            {
                Texture tex = new Texture();
                sampler.Texture = tex;
                if (iscolor)
                {
                    tex.Name            = "magicmirror.kinect.colorimage";
                    Kinect.ColorTexture = tex;
                }
                else
                {
                    tex.Name            = "magicmirror.kinect.depthimage";
                    Kinect.DepthTexture = tex;
                }
            }
            sampler.Name = "diffuse";
            sampler.Set(Sampler.TEXTUREOP, Sampler.DIFFUSE);
            sampler.Set(Sampler.TEXCOORD, 0);
            app.Set(Appearance.CULLING, 1);
            app.Set(Appearance.LIGHTING, 1);
            app.Set(Appearance.TRANSPARENCY, 1);
            app.SetSampler(0, sampler);
            app.Material     = mtl;
            app.Name         = "cameraoutput";
            shape.Appearance = app;
            GeoUtil.Rect(mesh, h * videosize.x / videosize.y, h, videosize.x / texsize.x, videosize.y / texsize.y);
            shape.Geometry = mesh;
            shape.Name     = "magicmirror.kinect.camerashape";
            shape.Translate(0, h / 2, -backdist);
            return(shape);
        }