Exemple #1
0
        /// <summary>
        /// Takes the Dynamic effect and converts it to a Keyframed Animation :P
        /// </summary>
        /// <param name="startFrame"></param>
        /// <param name="endFrame"></param>
        /// <param name="currentFrame"></param>
        public void DynamicsToKeys(int startFrame, int endFrame, int currentFrame)
        {
            float x_change     = 0.0f;
            float y_change     = 0.0f;
            float z_change     = 0.0f;
            int   keyFrequency = 10;
            float time;

            for (int i = startFrame; i <= endFrame; i += keyFrequency)
            {
                foreach (Object3DDynamics currentEffect in dynamicsList)
                {
                    switch (currentEffect.Name)
                    {
                    case "gravity":
                        float gravity = -0.0981f;
                        time = (float)(i - currentEffect.Index);
                        time = time < 0 ? 0 : time;
                        float velocity = (gravity * time * time) * 0.05f;
                        //float distance = (1/2)*velocity*time;

                        //x_change += currentEffect.Memento.translation.X + velocity;
                        y_change = velocity;

                        break;

                    case "vortex":
                        time = (float)(i - currentEffect.Index);
                        time = time < 0 ? 0 : time;
                        float x_amplitude = (float)(time * 0.05f);
                        float z_amplitude = (float)(time * 0.05f);
                        float x_speed     = 0.1f;
                        float z_speed     = 0.1f;
                        x_change = (float)Math.Sin((double)time * x_speed) * x_amplitude;
                        //+ currentEffect.Memento.translation.X;
                        z_change = ((float)Math.Cos((double)time * z_speed) - 1) * z_amplitude;
                        //+ currentEffect.Memento.translation.Z;
                        break;

                    default:
                        break;
                    }

                    AxisValue translateChange = new AxisValue(
                        (currentEffect.Memento.translation.X + x_change),
                        (currentEffect.Memento.translation.Y + y_change),
                        (currentEffect.Memento.translation.Z + z_change));

                    if (keyFrameList == null)
                    {
                        keyFrameList = new ArrayList();
                    }
                    RemoveKeyFrame(i);
                    keyFrameList.Add(new Object3DKeyFrame(i, new Object3DMemento(translateChange, rotation, scaling)));
                }
            }
            keyFrameList.Sort();
            this.dynamicsList.Clear();
            this.isDynamic = false;
        }
Exemple #2
0
        public Object3DCommon()
        {
            this.rotationMatrix    = Matrix.Identity;
            this.scalingMatrix     = Matrix.Identity;
            this.translationMatrix = Matrix.Identity;

            translation = new AxisValue();
            rotation    = new AxisValue();
            scaling     = new AxisValue();

            pivotPoint = new AxisValue();

            material = new Midget.Materials.MidgetMaterial();

            dynamicsList = new ArrayList();

            scaling.X = 1;
            scaling.Y = 1;
            scaling.Z = 1;

            lastFrameInterpolated = -1;

            selected = false;

            selectedMaterial          = new Midget.Materials.MidgetMaterial();
            selectedMaterial.Emissive = System.Drawing.Color.Snow;
            selectedMaterial.Diffuse  = System.Drawing.Color.White;
        }
Exemple #3
0
 internal Object3DDynamics(string dynamicName, Object3DMemento memento, int index)
 {
     _dynamicName        = dynamicName;
     _memento            = memento;
     _translateIncrement = new AxisValue();
     _index = index;
 }
Exemple #4
0
 internal Object3DKeyFrame(int index, Object3DMemento memento)
 {
     _index              = index;
     _memento            = memento;
     _translateIncrement = new AxisValue();
     _scaleIncrement     = new AxisValue();
     _rotateIncrement    = new AxisValue();
 }
Exemple #5
0
        //		private void PictureBox3D_SelectObject(object sender, Midget.Event.SelectObjectEventArgs e)
        //		{
        //			// if the user is not selecting multiple objects, clear the list
        //			if (!GetAsyncKeyState(ShiftKey))
        //			{
        //				selectedObjects.Clear();
        //			}
        //
        //			// add the selected object to the list
        //			selectedObjects.Add(e.SelectedObject);
        //
        //		}

        #region MouseEvents

        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            if (!GetAsyncKeyState(ArcBall.CameraControlKey))
            {
                if (e.Button == MouseButtons.Left)
                {
                    // object: movement

                    // start the object movement
                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    if (sm.SelectedObjects.Count > 0)
                    {
                        IObject3D selObject = (IObject3D)sm.SelectedObjects[sm.SelectedObjects.Count - 1];

                        // set cursors and initial object movement values
                        if (_editMode == EditMode.None)
                        {
                            this.Cursor = Cursors.Default;
                        }
                        else if (_editMode == EditMode.Move)
                        {
                            this.Cursor    = new Cursor(GetType(), "move.cur");
                            _startMovement = selObject.Translation;
                        }
                        else if (_editMode == EditMode.Rotate)
                        {
                            this.Cursor    = new Cursor(GetType(), "rotate.cur");
                            _startRotation = selObject.Rotation;
                        }
                        else if (_editMode == EditMode.Scale)
                        {
                            this.Cursor   = new Cursor(GetType(), "zoom.cur");
                            _startScaling = selObject.Scaling;
                        }
                    }
                }
            }

            base.OnMouseDown(e);
        }
Exemple #6
0
 internal Object3DKeyFrame(int index, Object3DMemento memento)
 {
     _index = index;
     _memento = memento;
     _translateIncrement = new AxisValue();
     _scaleIncrement = new AxisValue();
     _rotateIncrement = new AxisValue();
 }
Exemple #7
0
 internal Object3DDynamics(string dynamicName, Object3DMemento memento, int index)
 {
     _dynamicName = dynamicName;
     _memento = memento;
     _translateIncrement = new AxisValue();
     _index = index;
 }
Exemple #8
0
        private bool DidColide(IObject3D otherObject)
        {
            // check for self
            if (caller.Equals(otherObject))
            {
                return(false);
            }

            if ((caller is MeshObject) && (otherObject is MeshObject))
            {
                float callerRadius = 0.0f;                // Radius of bounding sphere of object
                float otherRadius  = 0.0f;                // Radius of bounding sphere of object

                // Retrieve the vertex buffer data in the mesh object
                VertexBuffer vb  = ((MeshObject)caller).mesh.VertexBuffer;
                VertexBuffer vb2 = ((MeshObject)otherObject).mesh.VertexBuffer;


                // Lock the vertex buffer to generate a simple bounding sphere
                GraphicsStream vertexData = vb.Lock(0, 0, LockFlags.NoSystemLock);
                callerRadius = Geometry.ComputeBoundingSphere(vertexData,
                                                              ((MeshObject)caller).mesh.NumberVertices,
                                                              ((MeshObject)caller).mesh.VertexFormat,
                                                              out callerCenter);
                vb.Unlock();
                vb.Dispose();


                // Lock the vertex buffer to generate a simple bounding sphere
                GraphicsStream vertexData2 = vb2.Lock(0, 0, LockFlags.NoSystemLock);
                otherRadius = Geometry.ComputeBoundingSphere(vertexData2,
                                                             ((MeshObject)otherObject).mesh.NumberVertices,
                                                             ((MeshObject)otherObject).mesh.VertexFormat,
                                                             out otherObjectCenter);
                vb2.Unlock();
                vb2.Dispose();

                // these couple of lines scale the bounding sphere down or up compared to the largest scaling of the x, y or z
                AxisValue callerScaling = caller.Scaling;
                callerRadius *= Math.Max(Math.Max(callerScaling.X, callerScaling.Y), callerScaling.Z);

                AxisValue otherObjectScaling = otherObject.Scaling;
                callerRadius *= Math.Max(Math.Max(otherObjectScaling.X, otherObjectScaling.Y), otherObjectScaling.Z);


                callerCenter.X = callerCenter.X + caller.Translation.X;
                callerCenter.Y = callerCenter.Y + caller.Translation.Y;
                callerCenter.Z = callerCenter.Z + caller.Translation.Z;

                otherObjectCenter.X = otherObjectCenter.X + otherObject.Translation.X;
                otherObjectCenter.Y = otherObjectCenter.Y + otherObject.Translation.Y;
                otherObjectCenter.Z = otherObjectCenter.Z + otherObject.Translation.Z;

                if (caller.GetVertDist(callerCenter, otherObjectCenter) > (callerRadius + otherRadius))
                {
                    return(false);
                }


                return(true);
            }
            return(false);
        }
        public void Execute()
        {
            //calcualte relative change
            AxisValue relativeChange = new AxisValue(X,Y,Z) - ((IObject3D)objects[objects.Count - 1]).PivotPoint;

            foreach (IObject3D obj in objects)
            {
                pivotPoints.Add(obj.PivotPoint);

                obj.PivotPoint = new AxisValue(obj.PivotPoint.X + relativeChange.X,
                    obj.PivotPoint.Y + relativeChange.Y ,
                    obj.PivotPoint.Z + relativeChange.Z);
            }

            Midget.Events.EventFactory.Instance.GenerateTransformationEvent(this,objects);
        }
        public void Execute()
        {
            //calcualte relative change
            AxisValue relativeChange = new AxisValue(X,Y,Z) - ((IObject3D)objects[objects.Count - 1]).Translation;

            foreach (IObject3D obj in objects)
            {
                mementos.Add(obj.CreateMemento());

                obj.Translate(obj.Translation.X + relativeChange.X,
                    obj.Translation.Y + relativeChange.Y ,
                    obj.Translation.Z + relativeChange.Z);

                // change active objects' memento
                if (obj.Rigidity == Rigidity.Active)
                {
                    obj.DynamicStartMemento = obj.CreateMemento();
                }
            }

            Midget.Events.EventFactory.Instance.GenerateTransformationEvent(this,objects);
        }
Exemple #11
0
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if ( !GetAsyncKeyState(ArcBall.CameraControlKey) && (e.Button == MouseButtons.Left) && selectedObjects.Count != 0 )
            {

                if (_editMode == EditMode.Rotate)
                {

                    Vector3 direction = camera.TargetPoint - camera.EyePosition;
                    Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
                    Vector3 upVector = camera.UpVector;

                    horizontal.Normalize();
                    upVector.Normalize();

                    float rotateX = (0.5f * (mouseDownX - e.X)) * upVector.X +
                        (0.5f * (e.Y - mouseDownY)) * horizontal.X + _startRotation.X;

                    float rotateY = (0.5f * (mouseDownX - e.X)) * upVector.Y +
                        (0.5f * (e.Y - mouseDownY)) * horizontal.Y + _startRotation.Y;

                    float rotateZ = (0.5f * (mouseDownX - e.X)) * upVector.Z +
                        (0.5f * (e.Y - mouseDownY)) * horizontal.Z + _startRotation.Z;

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this,selectedObjects,
                        new AxisValue(rotateX, rotateY, rotateZ),
                        Midget.Events.Object.Transformation.Transformation.Rotate);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
                else if (_editMode == EditMode.Move)
                {
                    // our picking
                    Vector3 pickRayOrigin = new Vector3();
                    Vector3 pickRayDir = new Vector3();
                    Vector3 pickRayOriginNew = new Vector3();
                    Vector3 pickRayDirNew = new Vector3();

                    Vector3 direction = camera.TargetPoint - camera.EyePosition;
                    Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
                    Vector3 upVector = camera.UpVector;

                    horizontal.Normalize();
                    upVector.Normalize();

                    // grab the last selected object
                    IObject3D selObj = (IObject3D)selectedObjects[selectedObjects.Count - 1];

                    // original mouse position
                    camera.UnProjectCoordinates(mouseDownX, mouseDownY, this.Width,
                        this.Height, ref pickRayOrigin, ref pickRayDir);

                    // new mouse position
                    camera.UnProjectCoordinates(e.X,
                        e.Y, this.Width,
                        this.Height, ref pickRayOriginNew, ref pickRayDirNew);

                    // transform by world and object model space
                    pickRayOrigin.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));
                    pickRayOriginNew.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));

                    // find the movement vector
                    Vector3 result = pickRayOriginNew - pickRayOrigin;

                    // pretty crappy compensation
                    if (this.Camera is PerspectiveMidgetCamera)
                    {
                        result *= 10.0f;
                    }

                    // generate an axis value to move by
                    AxisValue axes = new AxisValue(
                        selObj.Translation.X + result.X,
                        selObj.Translation.Y + result.Y,
                        selObj.Translation.Z + result.Z);

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this, selectedObjects,
                        axes,
                        Midget.Events.Object.Transformation.Transformation.Translate);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
                else if (_editMode == EditMode.Scale)
                {
                    float scaleX = 0.05f * (mouseDownX - e.X) + _startScaling.X;
                    float scaleY = 0.05f * (mouseDownY - e.Y) + _startScaling.Y;

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this,selectedObjects,
                        new AxisValue(scaleY,scaleY,scaleY),
                        Midget.Events.Object.Transformation.Transformation.Scale);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
            }

            base.OnMouseMove (e);
        }
Exemple #12
0
        public Object3DCommon()
        {
            this.rotationMatrix = Matrix.Identity;
            this.scalingMatrix = Matrix.Identity;
            this.translationMatrix = Matrix.Identity;

            translation = new AxisValue();
            rotation = new AxisValue();
            scaling = new AxisValue();

            pivotPoint = new AxisValue();

            material = new Midget.Materials.MidgetMaterial();

            dynamicsList = new ArrayList();

            scaling.X = 1;
            scaling.Y = 1;
            scaling.Z = 1;

            lastFrameInterpolated = -1;

            selected = false;

            selectedMaterial = new Midget.Materials.MidgetMaterial();
            selectedMaterial.Emissive = System.Drawing.Color.Snow;
            selectedMaterial.Diffuse = System.Drawing.Color.White;
        }
Exemple #13
0
 internal Object3DMemento(AxisValue translation, AxisValue rotation, AxisValue scaling)
 {
     this.translation = new AxisValue(translation);
     this.rotation    = new AxisValue(rotation);
     this.scaling     = new AxisValue(scaling);
 }
Exemple #14
0
 public AxisValue(AxisValue axisValue)
 {
     _x = axisValue.X;
     _y = axisValue.Y;
     _z = axisValue.Z;
 }
Exemple #15
0
 internal Object3DMemento(AxisValue translation, AxisValue rotation, AxisValue scaling)
 {
     this.translation	= new AxisValue (translation);
     this.rotation		= new AxisValue (rotation);
     this.scaling		= new AxisValue (scaling);
 }
Exemple #16
0
 public AxisValue(AxisValue axisValue)
 {
     _x = axisValue.X;
     _y = axisValue.Y;
     _z = axisValue.Z;
 }
Exemple #17
0
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (!GetAsyncKeyState(ArcBall.CameraControlKey) && (e.Button == MouseButtons.Left) && selectedObjects.Count != 0)
            {
                if (_editMode == EditMode.Rotate)
                {
                    Vector3 direction  = camera.TargetPoint - camera.EyePosition;
                    Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
                    Vector3 upVector   = camera.UpVector;

                    horizontal.Normalize();
                    upVector.Normalize();

                    float rotateX = (0.5f * (mouseDownX - e.X)) * upVector.X +
                                    (0.5f * (e.Y - mouseDownY)) * horizontal.X + _startRotation.X;

                    float rotateY = (0.5f * (mouseDownX - e.X)) * upVector.Y +
                                    (0.5f * (e.Y - mouseDownY)) * horizontal.Y + _startRotation.Y;

                    float rotateZ = (0.5f * (mouseDownX - e.X)) * upVector.Z +
                                    (0.5f * (e.Y - mouseDownY)) * horizontal.Z + _startRotation.Z;

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this, selectedObjects,
                                                                                           new AxisValue(rotateX, rotateY, rotateZ),
                                                                                           Midget.Events.Object.Transformation.Transformation.Rotate);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
                else if (_editMode == EditMode.Move)
                {
                    // our picking
                    Vector3 pickRayOrigin    = new Vector3();
                    Vector3 pickRayDir       = new Vector3();
                    Vector3 pickRayOriginNew = new Vector3();
                    Vector3 pickRayDirNew    = new Vector3();

                    Vector3 direction  = camera.TargetPoint - camera.EyePosition;
                    Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
                    Vector3 upVector   = camera.UpVector;

                    horizontal.Normalize();
                    upVector.Normalize();

                    // grab the last selected object
                    IObject3D selObj = (IObject3D)selectedObjects[selectedObjects.Count - 1];

                    // original mouse position
                    camera.UnProjectCoordinates(mouseDownX, mouseDownY, this.Width,
                                                this.Height, ref pickRayOrigin, ref pickRayDir);

                    // new mouse position
                    camera.UnProjectCoordinates(e.X,
                                                e.Y, this.Width,
                                                this.Height, ref pickRayOriginNew, ref pickRayDirNew);

                    // transform by world and object model space
                    pickRayOrigin.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));
                    pickRayOriginNew.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));

                    // find the movement vector
                    Vector3 result = pickRayOriginNew - pickRayOrigin;

                    // pretty crappy compensation
                    if (this.Camera is PerspectiveMidgetCamera)
                    {
                        result *= 10.0f;
                    }

                    // generate an axis value to move by
                    AxisValue axes = new AxisValue(
                        selObj.Translation.X + result.X,
                        selObj.Translation.Y + result.Y,
                        selObj.Translation.Z + result.Z);

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this, selectedObjects,
                                                                                           axes,
                                                                                           Midget.Events.Object.Transformation.Transformation.Translate);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
                else if (_editMode == EditMode.Scale)
                {
                    float scaleX = 0.05f * (mouseDownX - e.X) + _startScaling.X;
                    float scaleY = 0.05f * (mouseDownY - e.Y) + _startScaling.Y;

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this, selectedObjects,
                                                                                           new AxisValue(scaleY, scaleY, scaleY),
                                                                                           Midget.Events.Object.Transformation.Transformation.Scale);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
            }

            base.OnMouseMove(e);
        }
Exemple #18
0
        /// <summary>
        /// Takes the Dynamic effect and converts it to a Keyframed Animation :P
        /// </summary>
        /// <param name="startFrame"></param>
        /// <param name="endFrame"></param>
        /// <param name="currentFrame"></param>
        public void DynamicsToKeys(int startFrame, int endFrame, int currentFrame)
        {
            float x_change = 0.0f;
            float y_change = 0.0f;
            float z_change = 0.0f;
            int keyFrequency = 10;
            float time;

            for (int i = startFrame; i <= endFrame; i += keyFrequency)
            {
            foreach (Object3DDynamics currentEffect in dynamicsList)
            {

                    switch ( currentEffect.Name )
                    {
                        case "gravity":
                            float gravity = -0.0981f;
                            time = (float) (i - currentEffect.Index);
                            time = time < 0 ? 0 : time;
                            float velocity = (gravity * time * time) * 0.05f;
                            //float distance = (1/2)*velocity*time;

                            //x_change += currentEffect.Memento.translation.X + velocity;
                            y_change = velocity;

                            break;

                        case "vortex":
                            time = (float) (i - currentEffect.Index);
                            time = time < 0 ? 0 : time;
                            float x_amplitude = (float)(time * 0.05f);
                            float z_amplitude = (float)(time * 0.05f);
                            float x_speed = 0.1f;
                            float z_speed = 0.1f;
                            x_change = (float) Math.Sin((double) time * x_speed) * x_amplitude;
                            //+ currentEffect.Memento.translation.X;
                            z_change = ((float) Math.Cos((double) time * z_speed) -1) * z_amplitude;
                            //+ currentEffect.Memento.translation.Z;
                            break;

                        default:
                            break;

                    }

                    AxisValue translateChange = new AxisValue(
                        (currentEffect.Memento.translation.X + x_change),
                        (currentEffect.Memento.translation.Y + y_change),
                        (currentEffect.Memento.translation.Z + z_change));

                    if(keyFrameList	== null)
                    {
                        keyFrameList = new ArrayList();
                    }
                    RemoveKeyFrame(i);
                    keyFrameList.Add(new Object3DKeyFrame(i, new Object3DMemento(translateChange, rotation, scaling)));
                }
            }
            keyFrameList.Sort();
            this.dynamicsList.Clear();
            this.isDynamic = false;
        }
Exemple #19
0
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            if (!GetAsyncKeyState(ArcBall.CameraControlKey))
            {
                if (e.Button == MouseButtons.Left)
                {

                    // object: movement

                    // start the object movement
                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    if(sm.SelectedObjects.Count > 0)
                    {
                        IObject3D selObject = (IObject3D)sm.SelectedObjects[sm.SelectedObjects.Count - 1];

                        // set cursors and initial object movement values
                        if (_editMode == EditMode.None)
                        {
                            this.Cursor = Cursors.Default;
                        }
                        else if (_editMode == EditMode.Move)
                        {
                            this.Cursor = new Cursor(GetType(), "move.cur");
                            _startMovement = selObject.Translation;
                        }
                        else if (_editMode == EditMode.Rotate)
                        {
                            this.Cursor = new Cursor(GetType(), "rotate.cur");
                            _startRotation = selObject.Rotation;
                        }
                        else if (_editMode == EditMode.Scale)
                        {
                            this.Cursor = new Cursor(GetType(), "zoom.cur");
                            _startScaling = selObject.Scaling;
                        }
                    }
                }
            }

            base.OnMouseDown(e);
        }