Starting from:

$30

Project 1 - Transformation with Trackball

Project 1 - Transformation with Trackball
CS 1566 — Introduction to Computer Graphics
Check the Due Date on the CourseWeb
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 (40 Points)
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:
1
Zoom In and Zoom Out (10 Points)
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 (50 Points)
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:
2
x
y y
Front View Side View Top View
screen
screen
screen
z
z
x
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:
x
y y
Front View Side View Top View
screen
screen
screen
z
z
x
x
y y
Front View Side View Top View
screen
screen
screen
z
z
x
3
x
y y
Front View Side View Top View
screen
screen
screen
z
z
x
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.
Spinning an Object (Just for fun)
One special feature of this glass ball is that it can rotate indefinitely (no friction). If a user touches
the glass ball, drags his/her finger, and releases the finger, the glass ball should spin in the same
direction of the user’s finger indefinitely. Note that the zoom-in/zoom-out feature must work while
the object is spinning indefinitely.
4
Submission
The due date of this project is stated on the CourseWeb. Late submissions will not be accepted.
Zip all files related to this project into the file named project1.zip and submit it via CourseWeb.
After the due date, you must demonstrate your project to either TA or me within a week after the
due date.
5

More products