Implementation on Objective-C for Mac OS X, based on this article.
OpenGL
Rotate model with GLKit – Quaternions and Matrices math
I was looking for algorithm to apply additional rotation to model with current rotation matrix, and found this:
1
2 3 |
GLKVector3 up = GLKVector3Make(0.f, 1.f, 0.f);
up = GLKQuaternionRotateVector3( GLKQuaternionInvert(quarternion), up ); GLKQuaternion quarternion = GLKQuaternionMultiply(quarternion, GLKQuaternionMakeWithAngleAndVector3Axis(delta.x * RADIANS_PER_PIXEL, up)); |
It’s from this small tutorial about rotation:
A bit modified code, source here
Under code a bit more text and links
Continue reading
List of Anti-Aliasing techniques in 3D
I know about next Anti-Aliasing techniques:
MSAA – Multi-Sampled Anti-Aliasing
SSAA – Super-Sampled Anti-Aliasing also called FSAA
FXAA – Fast Approximate Anti-Aliasing, some good resource and this pdf
CSAA – Coverage Sample Anti-Aliasing
SMAA – Subpixel Morphological Anti-Aliasing
MLAA – Morphological Anti-Aliasing (OpenGL implementation)
If you know any other which is not in list, please write below in comment.
I will add them to list and links on page with description.
Print OpenGL error and description
Print OpenGL error:
1
2 3 4 |
GLenum err = glGetError();
if (err != GL_NO_ERROR) { NSLog(@"Error glGetError: glError: 0x%04X", err); } |
GL_INVALID_ENUM, 0×0500: Given when an enumeration parameter is not a legal enumeration for that function. This is given only for local problems; if the spec allows the enumeration in certain circumstances, and other parameters or state dictate those circumstances, then GL_INVALID_OPERATION is the result instead.
GL_INVALID_VALUE, 0×0501: Given when a value parameter is not a legal value for that function. This is only given for local problems; if the spec allows the value in certain circumstances, and other parameters or state dictate those circumstances, then GL_INVALID_OPERATION is the result instead.
GL_INVALID_OPERATION, 0×0502: Given when the set of state for a command is not legal for the parameters given to that command. It is also given for commands where combinations of parameters define what the legal parameters are.
GL_OUT_OF_MEMORY, 0×0503: Given when performing an operation that can allocate memory, but the memory cannot be allocated. The results of OpenGL functions that return this error are undefined; it is allowable for partial operations to happen.
GL_INVALID_FRAMEBUFFER_OPERATION, 0×0506: Given when doing anything that would attempt to read from or write/render to a framebuffer that is not complete, as defined here.
GL_STACK_OVERFLOW1, 0×0503: Given when a stack pushing operation cannot be done because it would overflow the limit of that stack’s size.
GL_STACK_UNDERFLOW1, 0×0504: Given when a stack popping operation cannot be done because the stack is already at its lowest point.
GL_TABLE_TOO_LARGE1, 0×8031: Part of the ARB_imaging extension.
GLKit, Opengl ES 2.0 Picking Ray for select object
Solution for picking
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
GLKVector4 normalisedVector = GLKVector4Make((2 * position.x / self.view.bounds.size.width - 1),
(2 * (self.view.bounds.size.height-position.y) / self.view.bounds.size.height - 1), -1, 1); GLKMatrix4 inversedMatrix = GLKMatrix4Invert(_modelViewProjectionMatrix, nil); GLKVector4 near_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector); near_point.v[3] = 1.0/near_point.v[3]; near_point = GLKVector4Make(near_point.v[0]*near_point.v[3], near_point.v[1]*near_point.v[3], near_point.v[2]*near_point.v[3], 1); normalisedVector.z = 1.0; GLKVector4 far_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector); far_point.v[3] = 1.0/far_point.v[3]; far_point = GLKVector4Make(far_point.v[0]*far_point.v[3], far_point.v[1]*far_point.v[3], far_point.v[2]*far_point.v[3], 1); |
On
Distance between vertices and magnitude of a vector
Distance between vertices:
1
2 3 4 5 6 7 8 9 10 11 12 13 |
static inline GLfloat Vertex3DDistanceBetweenVertices
(Vertex3D vertex1, Vertex3D vertex2) { GLfloat deltaX, deltaY, deltaZ; deltaX = vertex2.x - vertex1.x; deltaY = vertex2.y - vertex1.y; deltaZ = vertex2.z - vertex1.z; return sqrtf((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)); } |
Magnitude of a vector:
1
2 3 4 5 6 |
static inline GLfloat Vector3DMagnitude(Vector3D vector)
{ return sqrtf((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z)); } |