rejak

Members
  • Content count

    8
  • Joined

  • Last visited

Community Reputation

114 Neutral

About rejak

  • Rank
    Newbie
  1. thaaaaaaaaaaaaaaaaaaaaaaaaaaaanks Sponji and for me: MEGA FACEPALM
  2. void Camera::rotate_mouse(int16_t x, int16_t y) { glm::dvec3 rel = pos-tar; rel = glm::rotateX(rel, (double)y/10.0f); rel = glm::rotateY(rel, (double)x/10.0f); tar=pos+rel; //update(); //rotate((double)y/100.0f, glm::dvec3(1.0f, 0.0f, 0.0f)); //rotate((double)x/100.0f, glm::dvec3(0.0f, 1.0f, 0.0f)); } while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEMOTION: if (dragging) { graphics->get_camera()->rotate_mouse(event.motion.xrel, event.motion.yrel); } break; } } void Camera::update() { gluLookAt(pos[0], pos[1], pos[2], tar[0], tar[1], tar[2], up[0], up[1], up[2]); }
  3. Theres no need for screenshots, the flickering appears if i rotate the camera, at one frame you have a perfectly rendered scene the other frame you have a blank black screen. glClear clears the rendering buffer, so if you use doublebuffering it's indifferent if you call it at the top of the render function or on the bottom. Even it is on the bottom of the rendering function, it's before the next rendering function call. To be on the safe side i tried writing it on the top of the render function and it didn't made any differences, just the same flickering.
  4. The scene flickers if i rotate the camera with the mouse, sometimes if I release the mouse it keeps black until i rotate the camera again. If i release the mouse in a moment where the scene renders correctly, then the next frames are also rendered correctly. void Graphics_Engine::render(Hex_Board::hex_tile const * const * const tiles_list, uint16_t tiles_count) { double x, y, x_i, y_i; double angle; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); camera->update(); glColor3f( 0.0f, 1.0f, 0.0f); for (uint16_t i = 0; i < tiles_count; i++) { glBegin(GL_LINE_LOOP); x = sqrt(3.) * (tiles_list[i]->q + tiles_list[i]->r/2.); y = 3./2. * tiles_list[i]->r; for (uint8_t i = 0; i < 6; i++) { angle = 2. * M_PI / 6. * (i + 0.5); x_i = x + cos(angle); y_i = y + sin(angle); glVertex3f(x_i, y_i, 0); } glEnd(); } SDL_RenderPresent(renderer); glClear(GL_COLOR_BUFFER_BIT); } void Camera::update() { gluLookAt(pos[0], pos[1], pos[2], tar[0], tar[1], tar[2], up[0], up[1], up[2]); }
  5. thanks, one question: Is UP a direction vector relative to the position-target vector, or is it absolutley?
  6. I don't understand how glulookat works. I thought gluLookAt is a funtion you can tell, where the camera is, where the camera looks at and whats the upper side of the camera. So if you call gluLookAt multiple times with the same parameters nothing should change, but in my program the camera starts to rotate. void Graphics_Engine::render(Hex_Board::hex_tile const * const * const tiles_list, uint16_t tiles_count) { double x, y, x_i, y_i; double angle; glColor3f( 0.0f, 1.0f, 0.0f); //glRotatef(0.25, 1, 0.5, 0.1); gluLookAt(0.0f,0.0f,-5.0f,0.0f,0.0f,1.0f,1.0f,0.0f,0.0f); for (uint16_t i = 0; i < tiles_count; i++) { glBegin(GL_LINE_LOOP); x = sqrt(3.) * (tiles_list[i]->q + tiles_list[i]->r/2.); y = 3./2. * tiles_list[i]->r; for (uint8_t i = 0; i < 6; i++) { angle = 2. * M_PI / 6. * (i + 0.5); x_i = x + cos(angle); y_i = y + sin(angle); glVertex3f(x_i, y_i, 0); } glEnd(); } SDL_RenderPresent(renderer); glClear(GL_COLOR_BUFFER_BIT); }
  7. problem with quaternion camera

    Hmm, maybe i've explained the problem not right. I have a camera and if i move the mouse the camera should rotate but the camera should not move to an other point, just rotating. But I can see the objects placed in the world, when i move the camera from the other side. I can see the camera rotating AND the object a hexagonal tiled board, rotates very ugl arround himself. Edit: Even the camera rotation is correct. It rotates somehow but not in the right direction
  8. I have problems implementing a quaternion camera. It looks weird, it looks like the camera is not rotating but the object at the x,y-plane is rotating. class Camera { public: Camera(); virtual ~Camera(); void rotate_mouse(int16_t x, int16_t y); void rotate(double angle, glm::dvec3 axis); void update(); protected: private: glm::dvec3 pos; glm::dvec3 tar; glm::dvec3 up; }; Camera::Camera() : pos(0,0,-5), tar(0,0,1), up(1,0,0) { update(); } void Camera::rotate_mouse(int16_t x, int16_t y) { glm::dvec3 axis = glm::cross(tar-pos, up); glm::normalize(axis); rotate((double)y/1000.0f, axis); rotate((double)x/1000.0f, glm::dvec3(0.0f, 1.0f, 0.0f)); } void Camera::rotate(double angle, glm::dvec3 axis) { glm::dquat temp(cos(angle/2), axis.x * sin(angle/2), axis.y * sin(angle/2), axis.z * sin(angle/2)); glm::dquat quat_view(0, tar); glm::dquat result = (temp * quat_view) * glm::conjugate(temp); tar.x = result.x; tar.y = result.y; tar.z = result.z; } void Camera::update() { gluLookAt(pos[0], pos[1], pos[2], tar[0], tar[1], tar[2], up[0], up[1], up[2]); } case SDL_MOUSEMOTION: if (dragging) { //graphics->get_camera()->rotate(event.motion.xrel/1000000.0f, glm::vec3(0.f,1.f,0.f)); graphics->get_camera()->rotate_mouse(event.motion.xrel, event.motion.yrel); graphics->get_camera()->update(); } break;