Jump to content

[SOLVED]getPivotMatrix xyz local values


DigiHz Data
 Share

Recommended Posts

Hey let's all calm down a bit. At the moment I am looking into the jumping bit - its because all the rotations take place from zero not the current rotation. I am trying to help you with the rotation bit and not moving the mesh. Putting into a function, when I have solved that bit is not something I am interested in, but helping doing the rotation around a pivot is.

Link to comment
Share on other sites

@JohnK We have different appoaches you and me about this.

I do believe my approach is better. because it is in a function.

I not saying that your aproach is wrong.

I been struggling with this issue now for over 2 weeks, and when i finally  came up with a solution that can benefit most users (not only me), i felt proud of myself.

Many people in this forum have asked about a solution of this pivot moving without moving the mesh itself(values change of course).

Plz tell me what you think of my PG/approach.

EDIT: I thank you so very much for all the time you put into this.

Appriciated :)

Link to comment
Share on other sites

You have every right to be pleased with yourself for working it out, it is very gratifying to work on a tricky problem and to solve it. As you say my approach is different and I will continue working through my method until I am happy with it. We all think our own way is best. Happy coding.

Link to comment
Share on other sites

Updated PG.

http://www.babylonjs-playground.com/#M0UJB#1

Now uses a prototype.

BABYLON.Mesh.prototype.updatePivotPosition = function (axis, value)

(axis is either x y or z)

Example to use:

var result = mesh.updatePivotPosition('X',2.0);

result is the new position of the mesh(a vector3).

I PR this as soon as i get the time.

Link to comment
Share on other sites

Updated PG.

http://www.babylonjs-playground.com/#M0UJB#1

Now uses a prototype.

BABYLON.Mesh.prototype.updatePivotPosition = function (axis, value)

(axis is either x y or z)

Example to use:

var result = mesh.updatePivotPosition('X',2.0);

result is the new position of the mesh(a vector3).

I PR this as soon as i get the time.

I tried to do a pull request on github, but for some reason "Create pull request" is disabled.

@Deltakosh Can you do the pull request of my prototype.

BABYLON.Mesh.prototype.updatePivotPosition = function (axis, value) {
	var pivotCurrentValue = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(0, 0, 0), this.getPivotMatrix());
	if (axis.toLowerCase() === 'x'){
		this.setPivotMatrix(BABYLON.Matrix.Translation(value, pivotCurrentValue.y, pivotCurrentValue.z));
		this.translate(BABYLON.Axis.X, -(BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(0, 0, 0), this.getPivotMatrix()).x - pivotCurrentValue.x), BABYLON.Space.LOCAL);
	}
	else if (axis.toLowerCase() === 'y'){
		this.setPivotMatrix(BABYLON.Matrix.Translation(pivotCurrentValue.x, value, pivotCurrentValue.z));
		this.translate(BABYLON.Axis.Y, -(BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(0, 0, 0), this.getPivotMatrix()).y-pivotCurrentValue.y), BABYLON.Space.LOCAL);
	}
	else if (axis.toLowerCase() === 'z'){
		this.setPivotMatrix(BABYLON.Matrix.Translation(pivotCurrentValue.x, pivotCurrentValue.y, value));
		this.translate(BABYLON.Axis.Z, -(BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(0, 0, 0), this.getPivotMatrix()).z-pivotCurrentValue.z), BABYLON.Space.LOCAL);
	}
	else{
		throw new Error("Axis " + axis + " not supported, use x, y, or z");
	}
	return this.position;
};

 

 

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...