[comp.windows.x] 3d rotation in room coords?

tomt@maui.coral.COM (Tom Tulinsky) (03/05/91)

I'd like to allow the user to do 3d rotations of an object in the
'room' coordinate system; i.e. y is toward the ceiling, x is to his
right, and z is out of the screen (rt-handed).  I want this to be true
even after he has done some rotations....  The naive way of
implementing rotations accumulates them so that a 90 deg. y rotation,
the x axis is now pointing out of the screen, where the room z axis
is.  

I've tried everything I can think of, and can't get it to work.

My latest version, (using the Vogle package from uunet, somewhat like
SGI GL) does the y rotation, then tries to calculate where the xroom
vector is, and uses an arbitrary rotation routine to rotate about it.
The result: it just interchanges the order of rotations:  the X
axis is constant but the Y axis is rotated by xrot.  (also it only
works for y<0).

        while((but = slocator(&x, &y)) != 44) {    /* get mouse x,y */

              pushmatrix(); 
              {
                 color(BLACK);
                 clear();
                 yrot = 100.0*-x;
                 xrot = 100.0*-y;

                 rotate(yrot, 'y');    /* do y rot */

                 /* calc. xroom vector = Ry((1,0,0), -yrot) */

                 xroom[0] = cos(-yrot*D2R);
                 xroom[1] = 0.0;
                 xroom[2] = -sin(-yrot*D2R);
                 
                 /* do x rot */
                 rotarb (xroom[0],xroom[1],xroom[2],xrot);

                 callobj(obj);
                 callobj(GNOMON);
              }
              popmatrix();

/* rotarb--do rotation about an arbitrary vector 
 */
rotarb (a,b,c, theta)
float a,b,c,theta;
{
   float L, V, I, J;

   /* from Computer Graphics, Harrington, p 261. (modified) */

   L = sqrt(a*a + b*b + c*c);    /* lenght of vector */

   V = sqrt(b*b + c*c);          /* len of proj. on y-z plane */

   I = R2D*asin(b/V);      /* this is diff. from Harrington because I can't
   J = R2D*-asin(a/L);      * set rot mtx directly */
   
   rotate (I,'x');
   rotate (J,'y');
   rotate (theta,'z');
   rotate (-J,'y');
   rotate (-I,'x');
};



 Coral
     * **	Tom Tulinsky                508 460-6010
  *  **		Coral Network Corporation   fax 508 481-6258
*  ** 		734 Forest St               net: tomt@coral.com
 ***		   Marlboro, MA 01752		
  **		   U S A
*********	
NETWORKS	   

sundar@ai.mit.edu (Sundar Narasimhan) (03/06/91)

In article <9103050342.AA20065@maui.coral.com>, tomt@maui.coral.COM (Tom Tulinsky) writes:
|> 
|> I'd like to allow the user to do 3d rotations of an object in the
|> 'room' coordinate system; i.e. y is toward the ceiling, x is to his
|> right, and z is out of the screen (rt-handed).  I want this to be true
|> even after he has done some rotations....  The naive way of
|> implementing rotations accumulates them so that a 90 deg. y rotation,
|> the x axis is now pointing out of the screen, where the room z axis
|> is.  
|> 
|> I've tried everything I can think of, and can't get it to work.
|> 
|> My latest version, (using the Vogle package from uunet, somewhat like
|> SGI GL) does the y rotation, then tries to calculate where the xroom
|> vector is, and uses an arbitrary rotation routine to rotate about it.
|> The result: it just interchanges the order of rotations:  the X
|> axis is constant but the Y axis is rotated by xrot.  (also it only
|> works for y<0).
I understand what you want to do, but not what your implementation
does entirely. Here's what I have used in the past for something 
like this. (I'm assuming from your code, that you want your 
mouse to control viewer position).

Think of viewing the object from the surface of a sphere. Your eye
point can be specified by 2 co-ordinates (you can think of them
as latitude and longitude). Have your mouse motion map to these
co-ordinates. (For example, you can have up down motion map to
-90 to +90 degrees latitude wise, and your right-left motion map to
-180 to +180 degrees longitude wise). Once you have these co-ordinates
it is a simple matter to compute where the eye point is, and then
other things needed for graphics like the view vector and so on.
Maintain your up vector to be always up toward the ceiling.*

Hope this helps. 

* There is a subtlety associated with keeping the up vector pointing
up all the time (especially as your eye point gets way up and you are
looking almost directly down). If what you want are realistic fly-bys
then you can't keep the up-vector constant.

bernie@eric.ecr.mu.oz (Bernie Kirby) (03/06/91)

In article <9103050342.AA20065@maui.coral.com>, tomt@maui.coral.COM (Tom Tulinsky) writes:
> 
> I'd like to allow the user to do 3d rotations of an object in the
> 'room' coordinate system; i.e. y is toward the ceiling, x is to his
> right, and z is out of the screen (rt-handed).  I want this to be true
> even after he has done some rotations....  The naive way of
> implementing rotations accumulates them so that a 90 deg. y rotation,
> the x axis is now pointing out of the screen, where the room z axis
> is.  
> 
> I've tried everything I can think of, and can't get it to work.
> 
> My latest version, (using the Vogle package from uunet, somewhat like

	Here is a Vogle program that presents one alternative...
	When you press button 1 (on the mouse) it rotates about X,
	when you press button 2 (on the mouse) it rotates about Y,
	when you press button 3 (on the mouse) it rotates about Z.

	When you press all 3 buttons it exits.

	The rotations are proportional to the x position of the cursor
	and continue to accumulate as long as the button is pressed.

	Bernie.

----------
#include <vogle.h>
#define R2D	(1.0 / D2R)

main()
{
	int             but, i, j;
	float           x, y;
	float           x_rot, y_rot, zrot, xrot, yrot;

	prefsize(512, 512);
	vinit("");	/* Get device from envirionment */

	makeobj(1);
		color(1);
		move(0.0, 0.0, 0.0);
		draw(0.4, 0.0, 0.0);
		drawchar('x');
		color(2);
		move(0.0, 0.0, 0.0);
		draw(0.0, 0.4, 0.0);
		drawchar('y');
		color(3);
		move(0.0, 0.0, 0.0);
		draw(0.0, 0.0, 0.4);
		drawchar('z');
	closeobj();


	backbuffer();

	zrot = yrot = xrot = 0.0;

	while ((but = slocator(&x, &y)) <= 4) {	/* get mouse x,y */

		color(BLACK);
		clear();


		/*
		 * This one rotates about the normal orthogonal unrotated
		 * axes... but needs button 1 for about Y button 2 for
		 * about X, button 3 for Z.
		 */
		pushmatrix();	/* Save original... */
			translate(.4, 0.0, 0.0);
			rotate(yrot, 'y');
			rotate(xrot, 'x');
			rotate(zrot, 'z');
			if (but == 1) {
				xrot += 100.0 * -x;
			} else if (but == 2) {
				yrot += 100.0 * -x;
			} else if (but == 4) {
				zrot += 100.0 * -x;
			}

			callobj(1);
		popmatrix();
		/*
		 * This lot does it the normal way... ie if you rotate
		 * about the X-axis then rotate about Y the Y rotation
		 * is about the new X-rotated axis.
		 */
		pushmatrix();
			y_rot = 100.0 * -x;
			x_rot = 100.0 * -y;
			translate(-0.4, 0.0, 0.0);
			rotate(y_rot, 'y');	/* do y rot */
			rotate(x_rot, 'x');	/* do x rot */
			callobj(1);
		popmatrix();

		swapbuffers();
	}
}

sundar@ai.mit.edu (Sundar Narasimhan) (03/07/91)

In article <13709@life.ai.mit.edu>, sundar@ai.mit.edu (Sundar Narasimhan) writes:
|> In article <9103050342.AA20065@maui.coral.com>, tomt@maui.coral.COM (Tom Tulinsky) writes:
|> |> 
|> |> I'd like to allow the user to do 3d rotations of an object in the
|> |> 'room' coordinate system; i.e. y is toward the ceiling, x is to his
|> 
|> [ He basically wanted to view a room and be able to move his eye point
|> [ under mouse control. In response to this I wrote ...]
|>
|> Think of viewing the object from the surface of a sphere. Your eye
|> point can be specified by 2 co-ordinates (you can think of them
|> as latitude and longitude). Have your mouse motion map to these
|> co-ordinates ...

I have since been informed that Apple may have a patent pending on 
using this technique. I believe that this technique is NOT new, and
it could be classified as common knowledge amongst people in the 
graphics community.

Although I have not seen the actual patent application, I find it
somewhat disgusting that software companies are now seeking to
patent anything and everything under the sun. If you are too,
I'd advise you join the LPF (League for Programming Freedom) by
sending mail to league@prep.ai.mit.edu.

I'd also be interested in hearing about the actual patent application
and what it covers from anyone who knows about this.

Thanks in advance.

andreess@mrlaxs.mrl.uiuc.edu (Marc Andreessen) (03/07/91)

In article <13781@life.ai.mit.edu> sundar@ai.mit.edu writes:
>I have since been informed that Apple may have a patent pending on 
>using this technique.  [...concerning eyepoint as point on sphere]

Can someone post a number for this, if it's true?

Marc

--
Marc Andreessen___________University of Illinois Materials Research Laboratory
Internet: andreessen@uimrl7.mrl.uiuc.edu____________Bitnet: andreessen@uiucmrl

jsp@cs.ed.ac.uk (John Spackman) (03/07/91)

>|> Think of viewing the object from the surface of a sphere. Your eye
>|> point can be specified by 2 co-ordinates (you can think of them
>|> as latitude and longitude). Have your mouse motion map to these
>|> co-ordinates ...
>
>I have since been informed that Apple may have a patent pending on 
>using this technique. I believe that this technique is NOT new, and
>it could be classified as common knowledge amongst people in the 
>graphics community.
>

This technique is certainly not new.  It has been a feature available for
specifying views in Prime's MEDUSA CAD/CAM package for some years & was the
technique I used myself for post-graduate work over four years ago.

--
|: JANET: jsp@uk.ac.ed.lfcs :: ARPA: jsp%lfcs.ed.ac.uk@nsfnet-relay.ac.uk  :|
|: JANET: jsp@uk.ac.ed.castle: ARPA: jsp%castle.ed.ac.uk@nsfnet-relay.ac.uk:|
|: John Spackman, Computer Science, Edinburgh University, Room 2417 JCMB,  :|
|: The King's Buildings, Mayfield Road, Edinburgh EH9 3JZ. Tel 031 650 5125:|

raf@fib.upc.es (Rafal Korycinski) (03/07/91)

>Newsgroups: comp.windows.x,comp.graphics

In article <13781@life.ai.mit.edu> sundar@ai.mit.edu writes:
>I have since been informed that Apple may have a patent pending on 
>using this technique.  [...concerning eyepoint as point on sphere]

BTW: 	Do you know if some of Turing descendants has a patent pending
	on using computer ?

      /************************************************************************
     /   _        __   /           email:  raf@fib.upc.es                    /
    /   / |  __  /    /     phone:  +34-3-4016940     fax :  +34-3-4017040  /
   /   /_/  / / --   /-----------------------------------------------------/
  /   / \  /_/_ /   /    Disclaimer :                                     /
 /             /   /   And this is my opinion but I disagree with it.    /
************************************************************************/

naughton@wind.Eng.Sun.COM (Patrick Naughton) (03/08/91)

In article <1991Mar7.055600.4149@ux1.cso.uiuc.edu>, andreess@mrlaxs.mrl.uiuc.edu (Marc Andreessen) writes:
|> In article <13781@life.ai.mit.edu> sundar@ai.mit.edu writes:
|> >I have since been informed that Apple may have a patent pending on 
|> >using this technique.  [...concerning eyepoint as point on sphere]
|> 
|> Can someone post a number for this, if it's true?
|> 
|> Marc
|> 
|> --
|> Marc Andreessen______University of Illinois Materials Research Laboratory
|> Internet: andreessen@uimrl7.mrl.uiuc.edu_______Bitnet: andreessen@uiucmrl


I believe this is the paper we are talking about:

"A Study in Interactive 3-D Rotation Using 2-D Control Devices"
Michael Chen, S. Joy Mountford and Abigail Sellen
ACM Siggraph '88 proceedings (Volume 22, Number 4, August 1988).

and the technique which I think may have a patent pending is the
"Virtual Sphere Controller".

The principal author can be reached at:

	internet:	chen@apple.com
	AppleLink:	CHEN.M
	mail:		20525 Mariani Ave, MS 76-3H
			Cupertino, CA 95014

-Patrick

-- 
    ______________________________________________________________________
    Patrick J. Naughton				   email: naughton@sun.com
    Sun Laboratories				   voice: (415) 336 - 1080

hollasch@ENUXHA.EAS.ASU.EDU (Steve Hollasch) (03/08/91)

sundar@ai.mit.edu:
( I have since been informed that Apple may have a patent pending on 
( using this technique.  [...concerning eyepoint as point on sphere]

Marc Andreessen:
( Can someone post a number for this, if it's true?

Patrick Naughton:
( I believe this is the paper we are talking about:
(
( "A Study in Interactive 3-D Rotation Using 2-D Control Devices"
( Michael Chen, S. Joy Mountford and Abigail Sellen
( ACM Siggraph '88 proceedings (Volume 22, Number 4, August 1988).
( 
( and the technique which I think may have a patent pending is the
( "Virtual Sphere Controller".
( 
( The principal author can be reached at:
( 
( internet:chen@apple.com
( AppleLink:CHEN.M
( mail:20525 Mariani Ave, MS 76-3H
( Cupertino, CA 95014

    From what I understand, the virtual sphere controller is NOT a matter
of tieing lattitude and longitude to the mouse's X and Y axes.

    The virtual sphere is an imaginary sphere that encloses the object
under inspection.  To rotate the object, the user postitions the cursor
over this imaginary sphere and presses the mouse button.

    The display program maps the screen coordinates to the corresponding
point on the virtual sphere.  As the user drags the mouse cursor, the user
program rotates the object (and virtual sphere) so that the original
sphere point remains under the cursor.

    So, to rotate the object 360 degrees in the horizontal plane, you'd
click on the far side of the virtual sphere and drag the cursor to the
other side.  That's 180 degrees.  Repeat this operation and you've rotated
the object 360 degrees.

    When mapping mouse movement to the latitude and longitude of the eye
point, the relationship of mouse movement to rotation angle is linear.
This is not true for the virtual sphere device, where moving the cursor
near the borders of the sphere projection produces greater rotation
changes than moving the cursor near the center of the sphere face.

______________________________________________________________________________
Steve Hollasch                /      Arizona State University (Tempe, Arizona)
hollasch@enuxha.eas.asu.edu  /  uunet!mimsy!oddjob!noao!asuvax!enuxha!hollasch

sundar@ai.mit.edu (Sundar Narasimhan) (03/08/91)

|>
|>     When mapping mouse movement to the latitude and longitude of the eye
|> point, the relationship of mouse movement to rotation angle is linear.
|> This is not true for the virtual sphere device, where moving the cursor
|> near the borders of the sphere projection produces greater rotation
|> changes than moving the cursor near the center of the sphere face.
|> Steve Hollasch                /      Arizona State University (Tempe, Arizona)
|> hollasch@enuxha.eas.asu.edu  /  uunet!mimsy!oddjob!noao!asuvax!enuxha!hollasch

Ah yes.. Now I see. Introducing a sine (or a cosine) in the mapping 
between mouse to viewpoint co-ordinates clearly constitutes a
non-trivial extension that deserves a patent. Give me a break!

(BTW, this is exactly what I did in another program of mine).

nazgul@alphalpha.com (Kee Hinckley) (03/08/91)

In article <156*raf@fib.upc.es> raf@fib.upc.es (Rafal Korycinski) writes:
>BTW: 	Do you know if some of Turing descendants has a patent pending
>	on using computer ?
I find it somewhat unlikely that Turing had descendants.
The British government had him chemically castrated.
-- 
Alfalfa Software, Inc.          |       Poste:  The EMail for Unix
nazgul@alfalfa.com              |       Send Anything... Anywhere
617/646-7703 (voice/fax)        |       info@alfalfa.com

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

marbru@attc.UUCP (Martin Brunecky) (03/09/91)

In article <13825@life.ai.mit.edu> sundar@ai.mit.edu writes:
>Ah yes.. Now I see. Introducing a sine (or a cosine) in the mapping 
>between mouse to viewpoint co-ordinates clearly constitutes a
>non-trivial extension that deserves a patent. Give me a break!
>
   Isn't the most innovative part of any invention the discovery
   that it can be patented ?


-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                           {...}sunpeaks!auto-trol!marbru
(303) 252-2499                        (sometimes also:  marbru@auto-trol.COM )
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404 

aipdc@castle.ed.ac.uk (Paul Crowley) (03/11/91)

In article <1991Mar8.005915.7456@alphalpha.com> nazgul@alphalpha.com (Kee Hinckley) writes:
>In article <156*raf@fib.upc.es> raf@fib.upc.es (Rafal Korycinski) writes:
>>BTW: 	Do you know if some of Turing descendants has a patent pending
>>	on using computer ?
>I find it somewhat unlikely that Turing had descendants.
>The British government had him chemically castrated.

I don't think Turing was likely to have descendants in any case, and you
may be pleased to hear that the "treatment" had very little success -
he made a pretty quick recovery from it.  Of course, it was still a
barbaric act.
                                         ____
\/ o\ Paul Crowley aipdc@uk.ac.ed.castle \  /
/\__/ Part straight. Part gay. All queer. \/

lance@motcsd.csd.mot.com (lance.norskog) (03/13/91)

To view an object in a modelling application, I would rather move along
a hyperboloid (paraboloid? football!) whose foci are the endpoints of
the longest axis in the model.  This is often the camera path used in
SF movies where they spent lots of money on a big spaceship model and
really want to show it off.  I've heard of Bresenham ellipse-drawers;
it might be possible to cook up a fast football-walking 3D DDA.

Lance Norskog