Ejemplo n.º 1
0
        public void CreateProjectionMatrix()
        {
            var U = x;
            var V = y;
            var N = (Target - (Vector)Position).Normalize();
            var C = Position;
            int w = Width;
            int h = Height;
            //fieldOfViewX = fieldOfViewY*2.1f;

            var m1 = new Matrix4x4(w / 2.0f * ((float)Math.Tan(MathLab.Radians(fieldOfViewY * 0.5f))), 0, -w * 0.5f, 0,
                                   0, h / 2.0f * ((float)Math.Tan(MathLab.Radians(fieldOfViewX * 0.5f))), -h * 0.5f, 0,
                                   0, 0, 1, 0,
                                   0, 0, -1, 0);
            var m2 = new Matrix4x4(U.X, U.Y, U.Z, 0,
                                   V.X, V.Y, V.Z, 0,
                                   -N.X, -N.Y, -N.Z, 0,
                                   0, 0, 0, 1);
            var m3 = new Matrix4x4(1, 0, 0, -C.X,
                                   0, 1, 0, -C.Y,
                                   0, 0, 1, -C.Z,
                                   0, 0, 0, 1);
            this.projection = m1 * m2 * m3;
            projectTransform = new Transform(projection, Matrix4x4.Inverse(ref projection));

        }
Ejemplo n.º 2
0
 public EnvironmentCamera(Point position, int w, int h)
 {
     var mat = new Matrix4x4().Translate(position.x, position.y, position.z);
     world2Cam = new Transform(ref mat);
     this.rayOrigin = position;
     Width = w;
     Height = h;
 }
Ejemplo n.º 3
0
 public override void LookAt(Library.Core.Primitives.Point vector, Library.Core.Primitives.Point vector_2, Library.Core.Primitives.Vector vector_3)
 {
     var mat = new Matrix4x4().Translate(vector.x, vector.y, vector.z);
     world2Cam = new Transform(ref mat);
     this.rayOrigin = vector;
 }
Ejemplo n.º 4
0
        private SceneGraphInfo CreateSceneGraph( SceneGeometryInfo geoInfo,
                                                Transform worldTransform, 
                                                SceneGraphChangesType changes = SceneGraphChangesType.FullGraph ) {
            var scene = new SceneGraphInfo() { RootNode = new SceneGraphRootNode() };

            var cams = (cameras.Select(
                cameraInfo =>
                new {
                    cameraInfo,
                    camTransform = Transform.LookAt((Point)cameraInfo.Position, (Point)cameraInfo.Direction, cameraInfo.Up)
                })
                                   .Select(
                                       @t =>
                                       new CameraNode(@t.camTransform, @t.camTransform.GetInverse(), @t.cameraInfo) {
                                           Name = @t.cameraInfo.CameraName
                                       })).Cast<SceneGraphElement>().ToList();

            var scg = new SceneGeometryDataNode(worldTransform, worldTransform.GetInverse(), geoInfo);
            scene.RootNode.Children.Add(scg);

            var geoGroup = new GeometryGroupNode(worldTransform, worldTransform.GetInverse(), scg.Id) {FindRoot = scene.RootNode};
            scene.RootNode.Children.Add(geoGroup);

            var elements = geoInfo.Geometry.Select(
                geometryInfo => new { geometryInfo, geoTransform = new Transform()} )
                                      .Select(
                                          @t =>
                                          new GeometryElementNode(@t.geoTransform, @t.geoTransform.GetInverse(),
                                              @t.geometryInfo)).ToArray();

            geoGroup.Children.AddRange(elements);

            geoGroup.Children.AddRange(elements.Select(geoData => new GeometryInstanceNode(geoData.ObjectToWorld, geoData.WorldToObject, geoData.Id){ FindRoot = scg }));
            scene.RootNode.Children.AddRange(cams);
            scene.RootNode.Children.AddRange(mats.Select(item => new SceneMaterialDataNode(item)));
            scene.RootNode.Children.AddRange(this.lights.Select(item=>new LightsourceNode(null, null, item)));
            if (volumeMats != null && volumeMats.Any())
                scene.RootNode.Children.AddRange(volumeMats.Select(item=>new VolumeNode<VolumeMaterialInfo>(null, null, item)));
            scene.RootNode.WorldToObject = worldTransform;

            return scene;
        }
Ejemplo n.º 5
0
        public GeometryGroupNode(Transform o2w, Transform w2o, int did) : base(o2w, w2o, did)
        {

        }
Ejemplo n.º 6
0
 public CameraNode(Transform o2w, Transform w2o, CameraInfo camera) : base(o2w, w2o) {
     this.camera = camera;
 }
Ejemplo n.º 7
0
 protected SceneGraphElement(Transform o2w, Transform w2o) {
     this.ObjectToWorld = o2w;
     this.WorldToObject = w2o;
     this.Children = new List<SceneGraphElement>();
 }
Ejemplo n.º 8
0
 public void ApplyTransform(Transform m)
 {
     this.Org = m & this.Org;
     this.Dir = m & this.Dir;
 }
Ejemplo n.º 9
0
 public ReferenceNode(Transform o2w, Transform w2o, int did) : base(o2w, w2o)
 {
     this.DataNodeId = did;
 }
Ejemplo n.º 10
0
        public GeometryInstanceNode(Transform o2w, Transform w2o, int geoElementId) : base(o2w, w2o, geoElementId)
        {

        }