public SceneGraphNode CreateTestDOM()
        {
            SceneGraphNode document,
                           scene,
                           shape,
                           sphere;

            document = new X3D.X3D();
            scene    = new X3D.Scene();
            shape    = new X3D.Shape();
            sphere   = new X3D.Sphere();

            shape.Children.Add(sphere);
            scene.Children.Add(shape);
            document.Children.Add(scene);

            scene.Parent  = document;
            shape.Parent  = scene;
            sphere.Parent = shape;

            return(document);
        }
예제 #2
0
        private Matrix4 calculateModelview(
            Shape transform_context,
            RenderingContext rc
            )
        {
            Matrix4 MVP;
            Matrix4 model; // applied transformation hierarchy
            Matrix4 cameraRot;

            MVP = Matrix4.Identity;


            List <Transform> transformationHierarchy = transform_context
                                                       .AscendantByType <Transform>()
                                                       .Select(t => (Transform)t)
                                                       .Where(t => t.Hidden == false)
                                                       .ToList();

            Matrix4 modelview = Matrix4.Identity * rc.matricies.worldview;
            Vector3 x3dScale  = new Vector3(0.06f, 0.06f, 0.06f);

            Quaternion modelrotation      = Quaternion.Identity;
            Matrix4    modelLocalRotation = Matrix4.Identity;
            Matrix4    localTranslations  = Matrix4.Identity;
            Vector3    transAccum         = Vector3.Zero;

            foreach (Transform transform in transformationHierarchy)
            {
                transAccum += transform.Translation;

                //localTranslations *= Matrix4.CreateTranslation(transform.Translation * x3dScale);
                localTranslations = SceneEntity.ApplyX3DTransform(Vector3.Zero,
                                                                  Vector3.Zero,
                                                                  Vector3.One,
                                                                  Vector3.Zero,
                                                                  transform.Translation * x3dScale,
                                                                  localTranslations);
                modelview *= localTranslations;
            }

            //Vector3 p = Vector3.Zero;
            //Vector3 p = transform_context.GetPosition(rc);
            //Vector3 p2 = localTranslations.ExtractTranslation();
            //Vector3 origin = Vector3.Zero;
            //float dist = Vector3.Dot(origin, p2);
            //var p = p2 - new Vector3(dist);

            //Center = (new Vector3(((Width - p.X) / 2f), ( (Height-p.Y) / 2f), ((Depth - p.Z) / 2f) ) * x3dScale);
            //var Center2 = (new Vector3(((Width) / 2f), ((Height) / 2f), ((Depth) / 2f)) * x3dScale);
            //var top = (new Vector3((Width - p.X), (Height - p.Y) , (Depth - p.Z))) * x3dScale;
            //var left = Center + ((new Vector3(0, 0, Depth) * x3dScale));
            //var top = (new Vector3(Width - (Width / 2), Height, Depth)) * x3dScale;

            //localTranslations = Matrix4.Identity;

            //Position = (localTranslations.ExtractTranslation());

            //Quaternion qlocal = QuaternionExtensions.EulerToQuat(0, MathHelpers.PI, 0);
            //modelLocalRotation = Matrix4.CreateFromQuaternion(qlocal);

            //modelview = Matrix4.CreateTranslation(Position);

            //float distZ = Math.Abs(Maximum.Z) - Math.Abs(Minimum.Z);

            Vector3 center = new Vector3(Width / 2.0f, Height / 2.0f, Depth / 2.0f);


            Vector3 translation = new Vector3(
                //(((Minimum.X + (Maximum.X / 2.0f)) / 2.0f) ),
                //(((Minimum.Y + (Maximum.Y / 2.0f)) / 2.0f)),
                //(((Minimum.Z + (Maximum.Z / 2.0f)) / 2.0f))
                //((((Maximum.X) - (((Width) / 2.0f)) + (Maximum.X )) / 2.0f)),
                //((((Maximum.Y) - (((Height ) / 2.0f)) + (Maximum.Y )) / 2.0f) ),
                //((((Maximum.Z) - (((Depth) / 2.0f)) + (Maximum.Z)) / 2.0f) )

                //(Minimum.X) + (Width / 2.0f),
                //(Minimum.Y) + (Height / 2.0f),
                //(Minimum.Z) +  (Depth / 2.0f)
                (Maximum.X) + (Width / 2.0f),
                (Maximum.Y) + (Height / 2.0f),
                (Maximum.Z) + (Depth / 2.0f)
                );



            modelview = SceneEntity.ApplyX3DTransform(
                Vector3.Zero,
                Vector3.Zero,
                Vector3.One,
                Vector3.Zero,
                (translation) * x3dScale,
                Matrix4.Identity);

            model = modelview;

            Matrix4 cameraTransl = Matrix4.CreateTranslation(rc.cam.Position);


            cameraRot = Matrix4.CreateFromQuaternion(rc.cam.Orientation); // cameraRot = MathHelpers.CreateRotation(ref q);


            MVP = ((model) * cameraTransl) * cameraRot;



            //Matrix4 translation = Matrix4.CreateTranslation(left);
            //Matrix4 scale = Matrix4.CreateScale(1.0f, 1.0f, 1.0f);
            //Matrix4 rotationX = Matrix4.CreateRotationX(0.0f); // MathHelpers.PI
            //Matrix4 rotationY = Matrix4.CreateRotationY(0.0f);
            //Matrix4 rotationZ = Matrix4.CreateRotationZ(0.0f);
            //Matrix4 _model = scale * translation * (rotationX * rotationY * rotationZ);
            //MVP = (_model * cameraTransl )* cameraRot;

            return(MVP);
        }