Jump to content

New shorthand Vector3


Dad72
 Share

Recommended Posts

I do not know to use GitHub. :ph34r:  but I would like to propose new Vector3 shortened to supplement existing ones is Zero and Up.
Would you explain quickly Deltakosh  pull requests on GitHub.
 
babylon.Math

Vector3.Back= function (mesh, speed, gravity) {            if(speed === null) speed = 8;            if(gravity === null) gravity = -0.15;            var back = new BABYLON.Vector3(parseFloat(Math.sin(mesh.rotation.y)) / speed, gravity, parseFloat(Math.cos(mesh.rotation.y)) / speed);            return back.negate();};Vector3.Down = function () {             return new Vector3(0, -1.0, 0);};Vector3.Forward = function (mesh, speed, gravity) {            if(speed === null) speed = 8;            if(gravity === null) gravity = -0.15;            return new BABYLON.Vector3(parseFloat(Math.sin(mesh.rotation.y)) / speed, gravity, parseFloat(Math.cos(mesh.rotation.y)) / speed);};Vector3.Left = function () {             return new Vector3(-1.0, 0, 0);}; Vector3.One = function () {             return new Vector3(1.0, 1.0, 1.0);};Vector3.Right = function () {             return new Vector3(1, 0, 0);};// ExistVector3.Zero = function (){ ......

 [code edite]

 

Thanks

Edited by dad72
Link to comment
Share on other sites

Code that uses the result of these functions is going to have to take into account that the object may not be oriented facing forward on all axises.  I am doing POV movement & rotation of MORPH.Mesh objects, where you have no need to know.  May be just a style preference.

 

If doing it this way, it might be more useful to have an amount argument.

Link to comment
Share on other sites

There are already 2 done in the same way, I only complements here. I think it would be helpful

Vector3.Zero = function () {            return new Vector3(0, 0, 0);        };        Vector3.Up = function () {            return new Vector3(0, 1.0, 0);        };

exemple:

meshPlayer.moveWithCollisions(new BABYLON.Vector3.Forward());

or

meshPlayer.moveWithCollisions(new BABYLON.Vector3.Back());

 

Vector3.Up exists, why not Down ...

Link to comment
Share on other sites

Ok multipling is equivalent to an amount argument.  Could not taking its orientation into account mean your example would not actually go forward, as it is oriented?  I looked at the code for this, and have say I do not know what Mesh.ellipsoid is.  There is almost no code comments.  Does ellipsoid solve this?

        public moveWithCollisions(velocity: Vector3): void {            var globalPosition = this.getAbsolutePosition();            globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);            this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset);            this._collider.radius = this.ellipsoid;            this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions, this);            this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);            if (this._diffPositionForCollisions.length() > Engine.CollisionsEpsilon) {                this.position.addInPlace(this._diffPositionForCollisions);            }        }
Link to comment
Share on other sites

In complete you will have reasons, but if we do like this, it always works the front.
 
 

Vector3.Forward = function (mesh, speed, gravity) {            if(speed === null) speed = 8;            if(gravity === null) gravity = -0.15;            return new BABYLON.Vector3(parseFloat(Math.sin(mesh.rotation.y)) / speed, gravity, parseFloat(Math.cos(mesh.rotation.y)) / speed);};
Link to comment
Share on other sites

Your expanded example works for y axis rotation.  I was doing all-axis.  If you saw the flying table-cloth sample I did  https://googledrive.com/host/0B6-s6ZjHyEwUdHp3a3pJdlgwS0U, it did climbed a little as it moved forward, so Forward took into account more than y-rotation.  It also tilted right, which also affected "Forward".

 

For most, y axis only will be fine.  Here is my typescript:

        // ================================== Point of View Movement =================================        /**         * When the mesh is defined facing forward, multipliers must be set so that movePOV() is          * from the point of view of behind the front of the mesh.         * @param {boolean} definedFacingForward - True is the default         */        public setDefinedFacingForward(definedFacingForward : boolean) : void {            this._definedFacingForward = definedFacingForward;        }                /**         * Perform relative position change from the point of view of behind the front of the mesh.         * This is performed taking into account the meshes current rotation, so you do not have to care.         * Supports definition of mesh facing forward or backward.         * @param {number} amountRight         * @param {number} amountUp         * @param {number} amountForward         */        public movePOV(amountRight : number, amountUp : number, amountForward : number) : void {            this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));        }                /**         * Calculate relative position change from the point of view of behind the front of the mesh.         * This is performed taking into account the meshes current rotation, so you do not have to care.         * Supports definition of mesh facing forward or backward.         * @param {number} amountRight         * @param {number} amountUp         * @param {number} amountForward         */        public calcMovePOV(amountRight : number, amountUp : number, amountForward : number) : BABYLON.Vector3 {            var rotMatrix = new BABYLON.Matrix();            var rotQuaternion = (this.rotationQuaternion) ? this.rotationQuaternion : BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);            rotQuaternion.toRotationMatrix(rotMatrix);                        var translationDelta = BABYLON.Vector3.Zero();            var defForwardMult = this._definedFacingForward ? -1 : 1;            BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(amountRight * defForwardMult, amountUp, amountForward * defForwardMult, rotMatrix, translationDelta);            return translationDelta;        }        // ================================== Point of View Rotation =================================        /**         * Perform relative rotation change from the point of view of behind the front of the mesh.         * Supports definition of mesh facing forward or backward.         * @param {number} flipBack         * @param {number} twirlClockwise         * @param {number} tiltRight         */        public rotatePOV(flipBack : number, twirlClockwise : number, tiltRight : number) : void {            this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));        }                /**         * Calculate relative rotation change from the point of view of behind the front of the mesh.         * Supports definition of mesh facing forward or backward.         * @param {number} flipBack         * @param {number} twirlClockwise         * @param {number} tiltRight         */        public calcRotatePOV(flipBack : number, twirlClockwise : number, tiltRight : number) : BABYLON.Vector3 {            var defForwardMult = this._definedFacingForward ? 1 : -1;            return new BABYLON.Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);        }
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...