# Hector San Roman Lanza

Member

40

158 Neutral

• Rank
Member
1. ## Problem vehicle suspension formula - If damperForce is >0 then the vehicle is less stable...but It should be the opposite

But, It should be the opposite. If damperForce is >0 then the vehicle is more stable...   The code: // UNITY 5.4.0 //Constant values float suspensionLength = 1.0f; float stiffness = 0.4f; float dampingForce = 1.0f; void FixedUpdate()     {         RaycastHit hit;                 for (int i = 0; i < wheelPoints.Length; i++)         {             var wheelPoint = wheelPoints[i];             if (Physics.Raycast(wheelPoint.transform.position,                                 -transform.up,                                 out hit,                                 suspensionLength,                                 layerMask))             {                 float contactDepth = suspensionLength - hit.distance;                 float contactSpeed = contactDepth - lastContactDepth;                 float suspensionForce = stiffness * contactDepth + dampingForce * contactSpeed;                 suspensionForce *= 500;                 rigidBody.AddForceAtPosition(transform.up * suspensionForce, wheelPoints[i].transform.position, ForceMode.Force);                 lastContactDepth = contactDepth;             }         }     }
2. ## OpenGL Depth Texture without gradient and in red color

Hi! I render the depth texture to generate the shadow mapping.  I am following this tutorial: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/ In this tutorial, the author obtain a greyscale depthmap, but I obtain a red depth map without gradient. My code:         // After initialize the meshes and load the textures, generate the textures in OpenGL void Engine::GenerateTextures() {     // Generate the textures     textureCount = texturelist.size()+1; texturesID.reserve(textureCount);   // +1 to reserve space for depth texture glGenTextures(textureCount, &texturesID[0]);     int c = 0;     foreach(std::list<Texture*>, texturelist)     {         glActiveTexture(GL_TEXTURE0+c);         glBindTexture(GL_TEXTURE_2D, texturesID[c]);         ExitOnGLError("Error: Could not bind the texture");         glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, (*it)->width, (*it)->height, 0, GL_BGRA,GL_UNSIGNED_BYTE,(*it)->pixels );         ExitOnGLError("Error: Could not create the texture with glTexImage2D");         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);         glGenerateMipmap(GL_TEXTURE_2D);         c++;     }     // Initialize and binds the framebuffer.     ShadowFramebuffer = 0;     glGenFramebuffers(1, &ShadowFramebuffer);     glBindFramebuffer(GL_FRAMEBUFFER, ShadowFramebuffer);     // Generate the depth texture     glActiveTexture(GL_TEXTURE0+c);     glBindTexture(GL_TEXTURE_2D, texturesID[c]);     ExitOnGLError("Error: Could not bind the shadow texture");     glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT16, 1024, 1024, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);     ExitOnGLError("Error: Could not create the shadow texture with glTexImage2D");     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);     // Attach the texture to the framebuffer     glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  texturesID[c], 0);     ExitOnGLError("Error: Could not attach the texture to the frame buffer");     glDrawBuffer(GL_NONE); // No color buffer is drawn to.     ExitOnGLError("Error: Could not draw the buffer");     if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)         ExitOnGLError("Error: FrameBuffer isn´t OK");     glBindFramebuffer(GL_FRAMEBUFFER, 0); }     void Engine::Draw(void) {     drawDepthMap = true;     if(drawDepthMap)     {        // draw the objects using the depthRTT shader         foreach(std::list<GameScreen*>, gamescreens)         {             (*it)->Draw();         }     } }        depthRTT.glsl #ifdef COMPILING_VS layout(location=0) in vec4 in_Position; uniform mat4 ModelMatrix; uniform mat4 ViewMatrix; uniform mat4 ProjectionMatrix; void main(void) { gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position; } #endif #ifdef COMPILING_FS out float fragmentdepth; void main(void) { fragmentdepth = gl_FragCoord.z; } #endif    http://imageshack.us/photo/my-images/259/sinttulovbu.png/
3. ## Problem glDrawElements using GL_LINE_LOOP...deformed result

Hi! I try to render a mesh with GL_LINE_LOOP, but the result is deform:   This image show the vertex of the mesh and the indices:     The code to load and render:   void PhysicObject::Load(void) { glGenVertexArrays(1, &BufferIds[0]); ExitOnGLError("ERROR: No se puede generar el VAO"); glBindVertexArray(BufferIds[0]); ExitOnGLError("ERROR: No se puede bindear el VAO"); // Activamos dos vertex attribute locations glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); ExitOnGLError("ERROR: No se puede activar los vertex attributes"); // Creamos los VBO glGenBuffers(2, &BufferIds[1]); ExitOnGLError("ERROR: No se pueden generar los buffer objects"); // Bindeamos el VBO al VAO glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(VertexTextureNormal), &vertices[0], GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el VBO al VAO"); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertices[0]) ,0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertices[0]) , (GLvoid*) sizeof(vertices[0].position)); ExitOnGLError("ERROR: Could not set VAO attributes"); // Creamos el IBO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferIds[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices.front(), GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el IBO al VAO"); glBindVertexArray(0); } void PhysicObject::Draw() { std::cout<<c<<std::endl; // Create the ModelMatrix glm::mat4 ModelMatrix = glm::translate( glm::mat4(1.0f), getPosition() ); colormat->Prepare3dDraw(ModelMatrix); glBindVertexArray(BufferIds[0]); ExitOnGLError("ERROR: No se puede bindear el VAO para dibujar"); glDrawElements(GL_LINE_LOOP, indices.size(), GL_UNSIGNED_INT, (GLvoid*)0); ExitOnGLError("ERROR: No se puede dibujar el meshpart"); glBindVertexArray(0); }

5. ## glutKeyboardFunc takes 5 frames to update state

I am thinking to change to GLFW. Is reading inputs faster?
6. ## glutKeyboardFunc takes 5 frames to update state

I am using Freeglut.
7. ## glutKeyboardFunc takes 5 frames to update state

Hi! I have the keyboard class that initialize the glutKeyboards functions. When I release a key, the program takes five frames to detect. I have another class that when I push the key 's', it add a vec3(1.0,1.0,1.0) to the variable position. The problem is that in each frame from that I press key 's' until it detects that I released it adds to the variable position the vector vec3(1.0,1.0,1.0). The update() function is called before the Draw () function in the render method KeyboardDevice.cpp     void KeyboardDevice::keySpecialUp(int key, int x, int y) { keySpecialStates[key] = false; timeReleased = clock(); keySpecialReleaseStates[key] = true; // Set the state of the current special key recently pressed }   bool KeyboardDevice::IsKeyPress(unsigned char key) { return keyStates[key]; } bool KeyboardDevice::IsKeyUp(unsigned char key) { double now = clock()/(double)CLOCKS_PER_SEC; double last = timeReleased /(double)CLOCKS_PER_SEC; if(now-last < 1 && keyReleaseStates[key] == true) { keyReleaseStates[key] = false; return true; } return false; } Actor.cpp: void Cube::Update(void) { if(kb->IsKeyPress('s')) position += glm::vec3(1.0 * getParent()->getEngine()->deltaTime); } Any idea to resolve this?
8. ## GLSL initialize uniform variable with default value

If I not initialize the color variable in GLSL but I give a value through "glUniform3f(ColorUniformLocation, color.x, color.y, color.z);" in the code, it does´n work.  Am I doing something wrong?
9. ## GLSL initialize uniform variable with default value

Hi! I want to initialize my uniform variable in GLSL with a default value, but the program give me an error when I run it: Fragment code GLSL uniform vec3 Color = vec3(1.0,0.0,0.0); out vec3 out_Color; void main(void){ out_Color = Color; } If I the variable "Color" isn´t a uniform variable, the program works. I need that Color is uniform to change his value from a class. When I load the material I call this method:     void Color_mat::Load(void) { shader = getParent()->getEngine()->content.Load("Shaders/ColorShader.glsl"); Material::Load(); ColorUniformLocation = glGetUniformLocation(shader->ID, "Color"); ExitOnGLError("ERROR: Could not get the Color uniform location"); }       And When I draw, i call this method to start drawing the objects:   void Color_mat::Prepare3dDraw(glm::mat4 ModelMatrix) { Material::Prepare3dDraw(ModelMatrix); glUniform3f(ColorUniformLocation, color.x, color.y, color.z); ExitOnGLError("ERROR: Could not set the color"); }

11. ## Problem load multiple meshes

I discover my problem, the mesh variable from actor class...is static!!
12. ## Problem load multiple meshes

The problem isn´t the VAO or VBO. Before I load the cube, the plane have his data. After I load the cube, plane have the cube data. While the data cube load , the plane have the correctly data. I don´t know what its the problem. At least VBO and VAO are discarted.   Thanks for your attention.
13. ## Problem load multiple meshes

I add glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]) before calling DrawElements and it doesn´t work.
14. ## Problem load multiple meshes

the render function of meshparts:       void MeshPart::Draw() {     glBindVertexArray(BufferIds[0]);     ExitOnGLError("ERROR: No se puede bindear el VAO para dibujar");     glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (GLvoid*)0);     ExitOnGLError("ERROR: No se puede dibujar el meshpart");     glBindVertexArray(0); }
15. ## Problem load multiple meshes

Hi!   I have a method that load a mesh from .obj, and Initialice. It works when I load one mesh only...But If I load two o more different meshes, the first that I load take the values ( vertices, indices... ) from the second. I think that the problem is in VAO or VBO, but i can´t found the error.   There is the initialice method from Mesh Class:   void MeshPart::Initialize() { // Creamos el VAO glGenVertexArrays(1, &BufferIds[0]); ExitOnGLError("ERROR: No se puede generar el VAO"); glBindVertexArray(BufferIds[0]); ExitOnGLError("ERROR: No se puede bindear el VAO"); // Activamos dos vertex attribute locations glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); ExitOnGLError("ERROR: No se puede activar los vertex attributes"); // Creamos los VBO glGenBuffers(2, &BufferIds[1]); ExitOnGLError("ERROR: No se pueden generar los buffer objects"); // Bindeamos el VBO al VAO glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]); glBufferData(GL_ARRAY_BUFFER, vtn.size()*sizeof(VertexTextureNormal), &vtn[0], GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el VBO al VAO"); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vtn[0]) ,0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vtn[0]) , (GLvoid*) sizeof(vtn[0].position)); ExitOnGLError("ERROR: Could not set VAO attributes"); // Creamos el IBO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferIds[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices.front(), GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el IBO al VAO"); glBindVertexArray(0); }     Does anyone know what happens to me?