Jogl tessellation example3/20/2024 It's not hard to set the gl_FragDepth so that it properly intersects other geometry in the scene. I would use a GL_POINT and in the fragment shader generate the normals/shading/silhouette using the gl_PointCoord built-in vec2. You could have functions with the same signature that generate toruses, tractricoids, etc. One note for the above code: it actually generates the vertex data for an indexed triangle list mesh, there's also another function that generates the index data.Īlso notice that this function doesn't use the function for a sphere directly, that's passed in as a parameter. You could also just return a 4x4 matrix with the form: This way the function that maps a plane to a sphere can be written as such: void SphereSurfaceFunc(Vector2 UV, Vector3& P, Vector3& N, Vector3& T, Vector3& B)ĭualNum2 dU = DualNum2(Phi, The cross product of the two gives the normal vector at a given (u, v) location. Where it all comes together: the partial derivative of a parametric surface with respect to u gives the tangent vector at a given location, while the partial derivative with respect to v gives the bitangent/binormal vector. I won't go into the details but the dual numbers are closely related to the derivatives of functions, the "imaginary" part of a dual number (when plugged into an analytic function) can be interpreted as the derivative of the function at the location of the real part. For a sphere this is very simple, but there's a generalized way to get the tangent space at any point on a surface using dual numbers. Now, for actual rendering you need normal vectors and often also tangent and bitangent/binormal vectors (for normal mapping for example). This maps the region of your plane to the sphere. this way your function becomes: f(u, v) = This is relatively trivial, you can just interpret the u, v parameters as the angles in spherical coordinates. Say you have some f(u, v) -> R^3 function that maps the points of a plane to the points of a sphere. There's a pretty cool way to do this: surfaces can be described as an embedding of a 2D plane into 3D space. I would just generate a triangle strip on the CPU, put that in a vertex buffer and call it a day. draw left flat sphere with lines glPushMatrix() glTranslatef(-2.5f, 0, 0) glRotatef(cameraAngleX, 1, 0, 0) // pitch glRotatef(cameraAngleY, 0, 1, 0) // heading glRotatef(-90, 1, 0, 0) glBindTexture(GL_TEXTURE_2D, 0) sphere1.drawWithLines(lineColor) //sphere1.drawLines(lineColor) glPopMatrix() // draw centre smooth sphere with line glPushMatrix() glRotatef(cameraAngleX, 1, 0, 0) glRotatef(cameraAngleY, 0, 1, 0) glRotatef(-90, 1, 0, 0) glBindTexture(GL_TEXTURE_2D, 0) sphere2.drawWithLines(lineColor) glPopMatrix() // draw right sphere with texture glPushMatrix() glTranslatef(2.5f, 0, 0) glRotatef(cameraAngleX, 1, 0, 0) glRotatef(cameraAngleY, 0, 1, 0) glRotatef(-90, 1, 0, 0) glBindTexture(GL_TEXTURE_2D, texId) sphere2.draw() glPopMatrix() I'm in the middle of creating 3d pacman and have cubes for pellets and this hopefully will make them spheres instead.Īlthough i would question this in sphere's main.cpp (in regards to modern approach):
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |