TwoPointFive icon indicating copy to clipboard operation
TwoPointFive copied to clipboard

Rotating quad faces of a cube

Open bloxide opened this issue 5 years ago • 1 comments

Hi. I have a cube entity that draws faces of a cube, similar to what's mentioned in https://github.com/phoboslab/TwoPointFive/issues/7#issuecomment-514568338. I've managed to hack something together to manually rotate each face in tandem to simulate rotation of a cube but it's janky at best. Any advice of on how to do this properly?

I can see the loader rotates the camera around a cube, but in my case I need to rotate the actual cube itself, not the camera.

bloxide avatar Jun 12 '20 17:06 bloxide

In case it's helpful to anyone, while looking into a solution for the above, I added support for changing the pivot for quad rotations by modifying this._recalcPositions in quad.js:

	this.pivot = vec3.create();

        mat4.translate(m, m, this.position);

	if(piv[0] || piv[1] || piv[2]) {
		mat4.translate(m, m, [-this.pivot[0], -this.pivot[1], -this.pivot[2]]);	
	}

	if( rot[0] ) { mat4.rotateX(m, m, rot[0]); }
	if( rot[1] ) { mat4.rotateY(m, m, rot[1]); }
	if( rot[2] ) { mat4.rotateZ(m, m, rot[2]); }

	if(piv[0] || piv[1] || piv[2]) {
		mat4.translate(m, m, [this.pivot[0], this.pivot[1], this.pivot[2]]);
	}

Then adjust the pivot with:

	this.tile.quad.setPivot( x, y, z)

bloxide avatar Jun 12 '20 17:06 bloxide