Help me hack the view rotation!

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
makeshiftwings
Posts: 0
Joined: Wed Dec 03, 2003 4:12 am

Help me hack the view rotation!

Post by makeshiftwings »

I'd like to change the Blender view rotation controls so that the camera/view doesn't "roll", just yaw and pitch. Like the views in Wings3d, Milkshape, ZBrush, 3DSMax, Milkshape, etc. I'm used to coordinate systems where Y is up and Z is in, but I think in Blender Z is up and local Y would be in, so this might sound a little confused. I just need to find the code that rotates the view when you're dragging with the middle mouse button, and always set the camera's local Z axis to [0 0 1]. Is there an easy way to do this? The Blender code is really confusing to me; if someone could point me in the right direction I'd be grateful. I don't really need a checkbox or anything to turn it on, since I don't really ever want the viewport to roll. I would guess I could do something like the code below, but I don't know where it would go. The code below is an example from a 3d engine that uses Y as up, so I would substitue Z in blender. Here:

void Camera::yaw(const Radian& angle)
{
Vector3 yAxis;

if (mYawFixed)
{
// Rotate around fixed yaw axis. Usually Vector3::UNIT_Y.
yAxis = mYawFixedAxis;
}
else
{
// Rotate around local Y axis
yAxis = mOrientation * Vector3::UNIT_Y;
}

rotate(yAxis, angle);
}

ajk48n
Posts: 1
Joined: Sun Oct 27, 2002 12:10 am

Post by ajk48n »

first off, in case you don't know there is a turntable mode. It's under the user preference window in View and Controls

The file where the rotation occurs is:

CVS-Source\blender\source\blender\src\view.c

The viewmove procedure.

Under "if(mode==0)" is rotation.
There's trackball first, and turntable second.

I believe you also have to look at G.vd->persmat. That seems to be where Blender decides what direction is up when rotating in turntable mode.

makeshiftwings
Posts: 0
Joined: Wed Dec 03, 2003 4:12 am

Post by makeshiftwings »

ajk48n wrote:first off, in case you don't know there is a turntable mode. It's under the user preference window in View and Controls

The file where the rotation occurs is:

CVS-Source\blender\source\blender\src\view.c

The viewmove procedure.

Under "if(mode==0)" is rotation.
There's trackball first, and turntable second.

I believe you also have to look at G.vd->persmat. That seems to be where Blender decides what direction is up when rotating in turntable mode.
Thanks! I'll have a look. I do know about Turntable mode, however, it doesn't actually act like any kind of turntable I've ever seen ;). I'll probably switch my own copy to make Turntable act like the standard 3DSMax / Wings view, and leave Trackball as the weird tumbly Blender view if I ever decide I like it.

ajk48n
Posts: 1
Joined: Sun Oct 27, 2002 12:10 am

Post by ajk48n »

One other thing. It seems that when you are in turntable as it is, when you turn upside down, the object rotates the wrong way. After messing with it, I got this, which seems to fix the problem.

At the declarations in the viewmove procedure add:

float firstvec[3], newvec[3], dvec[3];
float oldquat[4], q1[4], si, phi, dist0;
int firsttime=1;
short mvalball[2], mval[2], mvalo[2];
int reverse; //<----------------------------add this line and down
reverse=1;
if (G.vd->persmat[2][1] < 0)
reverse*=-1;

Then in the turntable declaration add:

QuatMul(G.vd->viewquat, q1, oldquat);

/* rotate around z-axis (mouse x moves) */

phi= 2*(mval[0]-mvalball[0])*reverse; //<-----add the "*reverse"
phi/= (float)curarea->winx;
si= sin(phi);
q1[0]= cos(phi);
q1[1]= q1[2]= 0.0;
q1[3]= si;

Pierre-Luc_Auclair
Posts: 0
Joined: Tue Nov 23, 2004 1:57 am
Location: Quebec City, Canada
Contact:

Post by Pierre-Luc_Auclair »

Any update ?

I'd really like to see this added to Blender in a build soon ! :)

It would involve adding a new rotation mode though so people who like it like it is now won't complain.

I was wondering, is the "else" there where the problem lies ?

Code: Select all

if(mode==0) {	/* view rotate */

				if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 1;

				if (U.flag & USER_TRACKBALL) mvalball[0]= mval[0];
				mvalball[1]= mval[1];
				
				calctrackballvec(&curarea->winrct, mvalball, newvec);
				
				VecSubf(dvec, newvec, firstvec);
				
				si= sqrt(dvec[0]*dvec[0]+ dvec[1]*dvec[1]+ dvec[2]*dvec[2]);
				si/= (2.0*TRACKBALLSIZE);
			
				if (U.flag & USER_TRACKBALL) {
					Crossf(q1+1, firstvec, newvec);
	
					Normalise(q1+1);
	
					/* Allow for rotation beyond the interval
					 * [-pi, pi] */
					while (si > 1.0)
						si -= 2.0;
		
					/* This relation is used instead of
					 * phi = asin(si) so that the angle
					 * of rotation is linearly proportional
					 * to the distance that the mouse is
					 * dragged. */
					phi = si * M_PI / 2.0;
		
					si= sin(phi);
					q1[0]= cos(phi);
					q1[1]*= si;
					q1[2]*= si;
					q1[3]*= si;						
					QuatMul(G.vd->viewquat, q1, oldquat);
				} else {
					/* is there an acceptable solution? (180 degrees limitor) */
					if(si<1.0) {
						Crossf(q1+1, firstvec, newvec);
	
						Normalise(q1+1);
			
						phi= asin(si);
		
						si= sin(phi);
						q1[0]= cos(phi);
						q1[1]*= si;
						q1[2]*= si;
						q1[3]*= si;
						
						QuatMul(G.vd->viewquat, q1, oldquat);

						/* rotate around z-axis (mouse x moves)  */      <<<<<<<<<<<<<<<<<<< THERE  AND UNDER???
						
						phi= 2*(mval[0]-mvalball[0]);
						phi/= (float)curarea->winx;
						si= sin(phi);
						q1[0]= cos(phi);
						q1[1]= q1[2]= 0.0;
						q1[3]= si;
					
						QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
					}

rraallvv
Posts: 0
Joined: Thu Apr 04, 2013 5:59 pm

Post by rraallvv »

sorry for bumping this old topic, but this is a serious issue to me, Maya presets won't solve the Y-Z axis being swaped compared to Maya. Is there a way to do the hack by means of script add-on?

Maybe automatically correcting the Z axis to be completely vertical, while in the trackball orbit mode.

Ragards

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

Turntable mode keeps Z fixed. The point of trackball mode is that you can tumble about any axis.

You can play axis games with import/export scripts, but Blender's axis conventions are so deeply embedded in the code that changing it is difficult.

rraallvv
Posts: 0
Joined: Thu Apr 04, 2013 5:59 pm

Post by rraallvv »

stiv wrote:Turntable mode keeps Z fixed. The point of trackball mode is that you can tumble about any axis.

You can play axis games with import/export scripts, but Blender's axis conventions are so deeply embedded in the code that changing it is difficult.
Hmm... that is bad news, I guess I have to use trackball mode and get used to having no particular axis indicating where is upward.

gardian06
Posts: 0
Joined: Fri Jun 07, 2013 12:12 am

WHY?

Post by gardian06 »

rraallvv wrote:sorry for bumping this old topic, but this is a serious issue to me, Maya presets won't solve the Y-Z axis being swaped compared to Maya. Is there a way to do the hack by means of script add-on?

Maybe automatically correcting the Z axis to be completely vertical, while in the trackball orbit mode.

Ragards
that is not something that you just switch. basically every last calculation that references any kind of rotation, or even position movement would have to be rewritten, and in some cases it is not as simple as exchanging variable. in some you have to completely exchange the context of the equation you are using.

there is no absolute reason to have any axis as "up, in, or left". they are just a frame of reference, so that in 3D space you are able to understand what way you are pointing. then when you make the argument of conventions all you are really talking about is the first-phase decision being made by the developer(s) at the outset of the code base (see paragraph 1)

firstly there is no actual standard to label the axis anything specific just that there are 3 of them, and they are all orthogonal to each other. if the z axis is up that means it was designed by someone with a hardline math background (we have these 2 axis flat on the paper, and now we found a 3rd, well lets have it come out of the paper [up]), but if the y axis is up that means it was designed by someone with a physics background (we have all these equations that say gravity is in the negative y direction, and now there is a 3rd axis, so instead of rewriting all those equations just make it depth [in]) and engineering can pick and choose which one to use. the biggest thing is consistency once the decision is made.

in all reality the only real grounds for complaint would be if Blender did not allow for axis to be rotated, or switched during export. if that feature did not exist then the people asking for this axis interchange would have some argument, but otherwise my title stands "WHY?"

rraallvv
Posts: 0
Joined: Thu Apr 04, 2013 5:59 pm

Re: WHY?

Post by rraallvv »

gardian06 wrote: ... if the z axis is up that means it was designed by someone with a hardline math background (we have these 2 axis flat on the paper, and now we found a 3rd, well lets have it come out of the paper [up]), but if the y axis is up that means it was designed by someone with a physics background (we have all these equations that say gravity is in the negative y direction, and now there is a 3rd axis, so instead of rewriting all those equations just make it depth [in]) and engineering can pick and choose which one to use. the biggest thing is consistency once the decision is made.
Now the reason is pretty clear, thanks for clarifying.
gardian06 wrote: in all reality the only real grounds for complaint would be if Blender did not allow for axis to be rotated, or switched during export. if that feature did not exist then the people asking for this axis interchange would have some argument, but otherwise my title stands "WHY?"
It's because of the Bullet physics simulation, it doesn't allow to change which axis is up during exporting.

One solution is to rotate the whole thing and the run the simulation calling the export function.

Another option is to rotate the view to point Z upwards, but then the turntable navigation mode would have the main axis of rotation aligned horizontally.

Post Reply