Starting from:

$30

CS1566 -Project 1 Transformation with Trackball Solved

The purpose of this project is for you to transform (rotate and scale) an object in three dimensional space using a mouse.

Part I: 3D Objects
For this project, you need to create a computer generated three-dimensional object where each surface (triangle) of the object has a random color. For best result, the center of these objects must be at the origin. The maximum score of this part is 40 points. The score of this part will be based on the difficulty of the object you decide to create as follows:

•                   Cone: 15 Points

•                   Cylinder: 20 Points

•                   Tube: 25 Points

•                   Sphere: 30 Points

•                   Torus: 35 Points

•                   Spring: 40 Points Here are examples:

 

 

Zoom In and Zoom Out
For this project, we will use the scroll wheel of a mouse to scale an object. Scroll one way is an equivalent of enlarge an object in all direction about the origin by the factor of 1.02. Similarly, to shrink the object by the factor of 1/1.02 can be done by scrolling the other way.

Scrolling events are the same as mouse event. So, you need to call the glutMouseFunc() function to register your callback function:

glutMouseFunc(mouse);
where your mouse() function should look like the following:

void mouse(int button, int state, int x, int y)

{ :

}
If you scroll up, the mouse() function will be call with the variable button initialized to 3. Similarly, if you scroll down, the variable button will be initialized to 4. Simply apply the scaling matrix and call the glutPostRedisplay() function.

Note that if you use the track pad of your laptop, it may not registered as a scroll wheel. In this case, use a couple keys on your keyboard to perform zoom in and zoom out instead.

Trackball Style Rotation
To rotate an object in 3D, simply imagine that your object is located in the middle of a glass ball. This glass ball can be spun in any direction. Now, imagine that half of this glass ball pops out of your screen as shown below:

                                          y                                                                   y

 

z

                                  Front View                                         Side View                              Top View

From the above picture, there is a blue cube sitting inside this glass ball. If the glass ball is rotated, this cube is rotated as well.

Note that we a user click a mouse on the screen which is a two-dimensional surface, you have to imagine that the mouse pointer is a finger that touch the glass and point directly to the center of the glass ball in three-dimension. Mouse function only provide your x and y but you have to come up with your imaginary z since it is in three-dimensional space. Here are some examples:

                                          y                                                                   y

 

Front View
Side View
z

Top View
y
y
 
 

 
 
z
Front View
Side View
Top View
                                          y                                                                   y

 

z

                                  Front View                                         Side View                              Top View

To rotate the object inside this class ball, user needs to simply move his/her finger while touching the ball. For this project, assume that a user’s finger is always point directly to the origin while it is moving. Ideally, a user can twist his/her finger to rotate the glass ball. But since we cannot twist the mouse pointer, we assume that twisting the finger is not allow for this project. We will use left button of a mouse to simulate a user touches the glass ball. If the left button is down, user touches the ball at the current pointer position. If the left button is up, user released his/her finger from the ball. To capture the left button event, we use the same callback as in previous section. The variable button will be initialized to GLUT  LEFT BUTTON and the variable state will be initialized to either GLUT  UP or GLUT  DOWN. The variables x and y will be set to the pointer position. Note that the pointer position is the screen position. The top-left corner of the screen is at (0,0).

If the mouse pointer is moving while the left button is down, it simulates a user turning the glass ball. When the glass ball rotates, it rotates about a vector and the fixed point of rotation is at the origin. Your job is to come up with the vector so that you can apply rotation matrices correctly. A method of calculating this vector will be discussed in class.

To capture mouse motion events, use the glutMotionFunc() function as shown below:

glutMotionFunc(motion);
and the motion() function should look like the following:

void motion(int x, int y)

{ :

}
The variables x and y will be set to the current pointer position.

More products