hamidib/Open-GL-Track-Ball-Movement
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
The current mouse position and the previous mouse position are orignally stored in two seperate tuples. However these positions were related to the pixels on the screen rather than the orthognal base in 3D space. The first task was the convert these mouse postions as if they had been on the near plane rather than pixels. Using the mouse positions windowsize height/width and the nearplane halfheight/halfwidth the coordinates were changed on line 231, 232, 241 & 242 into cooresponding floating point numbers for the x and y values. I then converted these x and y values into a vec4 by adding mainCamera.near as the z, and 0 for w. The purpose of this was to project the new near plane coordinates into camera space by multiplying them by the lookAtMatrix. These new camera space coordinates where then passed to the shoemake function which calculated if the point selected on the near plane (p) landed on the sphere (P), and also new values for the selected point to relate to the surface of the sphere. With these two points the I then calculated the cross product and the dot product to get an axis of rotation and the angle of rotation. With these values I could then created the angleAxis which was then fed into a quaternion. The rotation matrix was then extracted from the quaternion and used to multiply against the modelViewMatrix.