normals

Adding a directional light to a transforming cube in vanilla wegl

℡╲_俬逩灬. 提交于 2019-12-12 20:55:35
问题 How can I add a direction light to a transforming cube in webGL. I know it requires normals and i've add them in the snippet (i've commented them out) It will also require some math in the vertex shader. unfortunatly this code doesnt work when i uncomment. attribute vec4 coords; uniform mat4 transformMatrix; attribute vec3 normal; attribute vec4 colors; uniform vec3 lightColor; uniform vec3 lightDirection; varying vec4 varyingColors; uniform mat4 perspectiveMatrix; void main(void) { vec3 norm

Issue aligning faces in Three.JS from two seperate objects

旧时模样 提交于 2019-12-12 04:52:19
问题 I'm having an issue in my three.js code. I am trying to align two objects by selecting two faces and have the second face (and object) rotate to match the normal vector of the first object's selected face. So far I have: var normalMatrix = new THREE.Matrix3().getNormalMatrix( object.matrixWorld ); var worldNormal = face.normal.clone().applyMatrix3( normalMatrix ).normalize(); var normalMatrixRef = new THREE.Matrix3().getNormalMatrix( objectRef.matrixWorld ); var worldNormalRef = faceRef

OpenGL normals misunderstanding?

狂风中的少年 提交于 2019-12-12 03:55:42
问题 I'm trying to get my lighting to work in OpenGL, using LWJGL as an implementation library. The problem I think I'm having, is that I don't set my normals properly and therefore the lighting doesn't work at certain angles. Here is the code for the cube I'm testing on: glBegin(GL_QUADS); glColor3f(r,g,b); glNormal3f(position.x, position.y, position.z - radius - 0.1f); glVertex3f(position.x + radius, position.y + radius, position.z - radius); glVertex3f(position.x + radius, position.y - radius,

transform cube to sphere in opengl

六月ゝ 毕业季﹏ 提交于 2019-12-12 03:08:10
问题 I am built some Cubes with the triangle approach (24 verticies per cube). Now I want to transform this cube to a sphere (maybe, I only want to have round corners) (later, I want to animate this transformation). How can I realize this? Can I use texture coordinates or normals to do this? I found this thread, but it doesn't help me. 回答1: To do this with simple OpenGL, you'll need to use a finer tessellate of the cube. Instead of drawing each face with only two triangles, you subdivide it into

Appearance of a triangle strip. Surface normals? Or windings?

我只是一个虾纸丫 提交于 2019-12-11 19:03:45
问题 Below is a picture of what my outcome is. I am using flat shading and have put each vertex in their respectable triangle objects. Then I use these vertices to calculate the surface normals. I have been reading that because my triangles share similar vertices that calculating the normals may be an issue? But to me this looks like a windings problem given that every other one is off. I provided some of my code below to anyone who wants to look through it and get a better idea what the issue

OpenGL, some normals reversed despite counterclockwise order

为君一笑 提交于 2019-12-11 14:12:15
问题 In the code below, I don't understand why some faces have their normals reversed. The triangles looks ordered in the anti-clockwise direction, but some faces remain black. When I modify the fragment shader with color = -vnormal; the two black faces are rendered correctly, but not the others, obviously. Thanks for any help given // minimalist but fonctional code using glew, glfw, glm #include <GL/glew.h> #include <GLFW/glfw3.h> #include <glm/vec3.hpp> #include <glm/vec4.hpp> #include <glm

Calculating the Normal Matrix in OpenGL

若如初见. 提交于 2019-12-11 07:51:51
问题 The following site says to use the model_view matrix when computing the normal matrix (assuming we are not using the built in gl_NormalMatrix): (site)Light House. I have the following algorithm in my program: //Calculate Normal matrix // 1. Multiply the model matrix by the view matrix and then grab the upper left // corner 3 x 3 matrix. mat3x3 mv_orientation = glext::orientation_matrix<float, glext::column>( glext::model_view<float, glext::column>(glext_model_, glext_view_)); // 2. Because

Trying to fix 3D mesh normals

有些话、适合烂在心里 提交于 2019-12-11 04:07:03
问题 I have triangle collection that define mesh surface of my 3D shape, I would like to fix normal of each triangle to point outshape. I was trying the following (pseudo): 1. define that first triangle normal direction is right direction 2. go over the mesh using kind of DFS like this: 3. triangle = first triangle 4. foreach neigbour in triangle.getNeighbours 5. if angle between neighbor and triangle greater then 180 do neighbor.flip() 6. triangle = neighbor 7. if neighbor already picked then

Normals acting weird in openGL

送分小仙女□ 提交于 2019-12-10 16:10:18
问题 I've been writing an .obj loader for openGl. The geometry loads in fine, but the normals are always messed up. I've tried to export models in 2 different programs and nothing seems to work. As far as I know, this is how you put in a normal to a GL_TRIANGLES glNormal3fv(norm1); glVertex3fv(vert1); glNormal3fv(norm2); glVertex3fv(vert2); glNormal3fv(norm3); glVertex3fv(vert3); (the normals are referencing to GLfloats in the rest of the code.) EDIT: Here is a picture of a isohedron with the

Loading an OBJ file, how to use normals (#vertices < #normals)

一世执手 提交于 2019-12-09 20:11:36
问题 I have an obj file and have succesfully loaded the object to opengl without using the normals given. This is how it looks: The format of the file is: v x y z vn x y z f x//x' y//y' z//z' The displaying function of the mesh is like that: glBegin(GL_TRIANGLES); for all faces { glVertex3f(.., .., ..); glVertex3f(.., .., ..); glVertex3f(.., .., ..); } glEnd(); And the result is this: I've read that the object might look flat due to the default normal vector that OpenGL uses for lighting equations