Transform Matrix and Pivot

Started by
11 comments, last by HaloMasterChief 8 years, 1 month ago

Hello phil_t,

with the X axis i meant only a example, i want to create a Transform Tool that can place a 3D Object in a Scene where i want, so in the end, I want to move and rotate it on all 3 axis, not only on one axis, how is there the solution?

Greets

Replace Vector3.UnitX with Vector3.UnitX, UnitY or UnitZ depending with object axis your tool is moving it along:


Vector3 worldTranslateDirection = Vector3.TransformNormal(Vector3.UnitX, rotation);
Advertisement


can you please make a example with my code, because in the Moment i can't understand what i meant?

phil_t's got you covered.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Hello phil_t,

Your Solution works perfect with one exception, if i want to set the cube on a special Point, as example of the X axis of 3, than he just added 3 steps to the translation with the rotated axis instead of to reset the cube of 3 of the X axis.

With = instead of += i haven't this problem, but than he rotate the cube only around the middle of the scene again 0, 0, 0, instead of around him self?

My Code:


        public void TranslateX(float units)
        {
                this.translate += this.localSide * units;
        }

        public void TranslateY(float units)
        {
                this.translate += this.localUp * units;
        }

        public void TranslateZ(float units)
        {
                this.translate += this.localLook * units;
        }

        public void _Rotate(Vector3 result)
        {
            this.rotate = result;
            this.rotation = Matrix.RotationYawPitchRoll(Mathematics.DegreesToRadians(this.rotate.Y),
                    Mathematics.DegreesToRadians(this.rotate.X),
                    Mathematics.DegreesToRadians(this.rotate.Z));

            this.localSide = Vector3.TransformNormal(Vector3.UnitX, this.rotation);
            this.localUp = Vector3.TransformNormal(Vector3.UnitY, this.rotation);
            this.localLook = Vector3.TransformNormal(Vector3.UnitZ, this.rotation);
        }

        public void _Scale(Vector3 result)
        {
            this.scale = result;
        }

        public void UpdateWorld()
        {
            Matrix scale = Matrix.Scaling(this.scale);
            Matrix translate = Matrix.Translation(this.translate);

            this.world = (scale * this.rotation * translate);
        }

Greets

This topic is closed to new replies.

Advertisement