Search Results

Search found 33 results on 2 pages for 'glulookat'.

Page 1/2 | 1 2  | Next Page >

  • Using gluLookAt to move camera in 2D iPhone game ?

    - by Mr.Gando
    Hey guys, I'm trying to use gluLookAt to move the camera in my iPhone game, but every time I've tried to use gluLookAt my screen just goes "blank" ( grey in this case ) I'm trying to render a simple triangle and to move the camera, this is my code: to setup my scene I do: glViewport(0, 0, backingWidth, backingHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glRotatef(-90.0, 0.0, 0.0, 1.0); //using iPhone in horizontal mode glOrthof(-240, 240, -160, 160, -1, 1); glMatrixMode(GL_MODELVIEW); then my "triangle rendering" code looks like: GLfloat triangle[] = {0, 100, 100, 0, -100, 0,}; glClearColor(0.7, 0.7, 0.7, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnableClientState(GL_VERTEX_ARRAY); glColor4f(1.0, 0.0, 0.0, 1.0); glVertexPointer(2, GL_FLOAT, 0, &triangle); glDrawArrays(GL_TRIANGLES, 0, 6); glDisableClientState(GL_VERTEX_ARRAY); This draws a red triangle in the middle of the screen, when I try to apply gluLookAt ( I got the implementation of the function from Cocos2D so I asume it's correct ), i do: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,1,0,0,0,0,0,1); // try to move the camera a bit ? GLfloat triangle[] = {0, 100, 100, 0, -100, 0,}; glClearColor(0.7, 0.7, 0.7, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnableClientState(GL_VERTEX_ARRAY); glColor4f(1.0, 0.0, 0.0, 1.0); glVertexPointer(2, GL_FLOAT, 0, &triangle); glDrawArrays(GL_TRIANGLES, 0, 6); glDisableClientState(GL_VERTEX_ARRAY); This leads me to grey screen (glClearColor is grey), I've tried all sort of things and read what I've found about gluLookAt on the net, but no luck :(, if someone could explain me or show me how to move to move the camera in a top-down fashion ( zelda, etc ), I would really appreciate it. Thanks!

    Read the article

  • gluLookAt vectors and FPS-style camera

    - by Kevin Pamplona
    I am attempting to implemented an FPS-style camera by updating three vectors: EYE, DIR, UP. These vectors are the same that are used by gluLookAt (since gluLookAt is specified by the position of the camera, the direction it is looking at, and an up vector). I have already implemented the left-right and up-down strafing movements, but I'm having a lot of trouble understanding the math behind making the camera look-around while remaining stationary. In this case, the EYE vector remains the same, while I must update DIR and UP. Below is the code I tried, but it doesn't seem to work properly. Any suggestions? Thanks. void Transform::left(float degrees, vec3& dir, vec3& up) { vec3 axis; axis = glm::normalize(up); mat3 R = rotate(-degrees, axis); dir = R*dir; dir = R*up; }; void Transform::up(float degrees, vec3& dir, vec3& up) { vec3 axis; axis=glm::normalize(glm::cross(dir,up)); mat3 R = rotate(-degrees, axis); dir = R*dir-; up = R*up; };

    Read the article

  • How does gluLookAt work?

    - by Chan
    From my understanding, gluLookAt( eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z ); is equivalent to: glRotatef(B, 0.0, 0.0, 1.0); glRotatef(A, wx, wy, wz); glTranslatef(-eye_x, -eye_y, -eye_z); But when I print out the ModelView matrix, the call to glTranslatef() doesn't seem to work properly. Here is the code snippet: #include <stdlib.h> #include <stdio.h> #include <GL/glut.h> #include <iomanip> #include <iostream> #include <string> using namespace std; static const int Rx = 0; static const int Ry = 1; static const int Rz = 2; static const int Ux = 4; static const int Uy = 5; static const int Uz = 6; static const int Ax = 8; static const int Ay = 9; static const int Az = 10; static const int Tx = 12; static const int Ty = 13; static const int Tz = 14; void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); GLfloat lmodel_ambient[] = { 0.8, 0.0, 0.0, 0.0 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); } void displayModelviewMatrix(float MV[16]) { int SPACING = 12; cout << left; cout << "\tMODELVIEW MATRIX\n"; cout << "--------------------------------------------------" << endl; cout << setw(SPACING) << "R" << setw(SPACING) << "U" << setw(SPACING) << "A" << setw(SPACING) << "T" << endl; cout << "--------------------------------------------------" << endl; cout << setw(SPACING) << MV[Rx] << setw(SPACING) << MV[Ux] << setw(SPACING) << MV[Ax] << setw(SPACING) << MV[Tx] << endl; cout << setw(SPACING) << MV[Ry] << setw(SPACING) << MV[Uy] << setw(SPACING) << MV[Ay] << setw(SPACING) << MV[Ty] << endl; cout << setw(SPACING) << MV[Rz] << setw(SPACING) << MV[Uz] << setw(SPACING) << MV[Az] << setw(SPACING) << MV[Tz] << endl; cout << setw(SPACING) << MV[3] << setw(SPACING) << MV[7] << setw(SPACING) << MV[11] << setw(SPACING) << MV[15] << endl; cout << "--------------------------------------------------" << endl; cout << endl; } void reshape(int w, int h) { float ratio = static_cast<float>(w)/h; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, ratio, 1.0, 425.0); } void draw() { float m[16]; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glGetFloatv(GL_MODELVIEW_MATRIX, m); gluLookAt( 300.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f ); glColor3f(1.0, 0.0, 0.0); glutSolidCube(100.0); glGetFloatv(GL_MODELVIEW_MATRIX, m); displayModelviewMatrix(m); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(400, 400); glutInitWindowPosition(100, 100); glutCreateWindow("Demo"); glutReshapeFunc(reshape); glutDisplayFunc(draw); init(); glutMainLoop(); return 0; } No matter what value I use for the eye vector: 300, 0, 0 or 0, 300, 0 or 0, 0, 300 the translation vector is the same, which doesn't make any sense because the order of code is in backward order so glTranslatef should run first, then the 2 rotations. Plus, the rotation matrix, is completely independent of the translation column (in the ModelView matrix), then what would cause this weird behavior? Here is the output with the eye vector is (0.0f, 300.0f, 0.0f) MODELVIEW MATRIX -------------------------------------------------- R U A T -------------------------------------------------- 0 0 0 0 0 0 0 0 0 1 0 -300 0 0 0 1 -------------------------------------------------- I would expect the T column to be (0, -300, 0)! So could anyone help me explain this? The implementation of gluLookAt from http://www.mesa3d.org void GLAPIENTRY gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz) { float forward[3], side[3], up[3]; GLfloat m[4][4]; forward[0] = centerx - eyex; forward[1] = centery - eyey; forward[2] = centerz - eyez; up[0] = upx; up[1] = upy; up[2] = upz; normalize(forward); /* Side = forward x up */ cross(forward, up, side); normalize(side); /* Recompute up as: up = side x forward */ cross(side, forward, up); __gluMakeIdentityf(&m[0][0]); m[0][0] = side[0]; m[1][0] = side[1]; m[2][0] = side[2]; m[0][1] = up[0]; m[1][1] = up[1]; m[2][1] = up[2]; m[0][2] = -forward[0]; m[1][2] = -forward[1]; m[2][2] = -forward[2]; glMultMatrixf(&m[0][0]); glTranslated(-eyex, -eyey, -eyez); }

    Read the article

  • Euler angles to Cartesian Coordinates for use with gluLookAt

    - by notrodash
    I have searched all of the internet but just couldn't find the answer. I am using LibGDX and this is part of my code that loops over and over: public void render() { GL11 gl = Gdx.gl11; float centerX = (float)Math.cos(yaw) * (float)Math.cos(pitch); float centerY = (float)Math.sin(yaw) * (float)Math.cos(pitch); float centerZ = (float)Math.sin(pitch); System.out.println(centerX+" "+centerY+" "+centerZ+" ~ "+GDXRacing.camera.position.x+" "+GDXRacing.camera.position.y+" "+GDXRacing.camera.position.z); Gdx.glu.gluLookAt(gl, GDXRacing.camera.position.x, GDXRacing.camera.position.y, GDXRacing.camera.position.z, centerX, centerY, centerZ, 0, 1, 0); if(Gdx.input.isKeyPressed(Keys.A)) { yaw--; } if(Gdx.input.isKeyPressed(Keys.D)) { yaw++; } } I might just be bad at the math, but I dont get it. Does someone have a good explanation and an idea about how to deal with this? I am trying to make a first person camera. By the way, the camera is translated by +10 on the Z axis. Currently when I run the application, this is what I get: Watch video in browser | Download video (for those who cant download the video, everything shakes in a clockwise/anticlockwise action, depending on if I increase or decrease the Yaw value) -Thank you. [edit] and with this code: public void render() { GL11 gl = Gdx.gl11; float centerX = (float)(MathUtils.cosDeg(yaw)*4); float centerY = 0; float centerZ = (float)(MathUtils.sinDeg(yaw)*4); System.out.println(centerX+" "+centerY+" "+centerZ+" ~ "+GDXRacing.camera.position.x+" "+GDXRacing.camera.position.y+" "+GDXRacing.camera.position.z); Gdx.glu.gluLookAt(gl, GDXRacing.camera.position.x, GDXRacing.camera.position.y, GDXRacing.camera.position.z, centerX, centerY, centerZ, 0, 1, 0); if(Gdx.input.isKeyPressed(Keys.A)) { yaw--; } if(Gdx.input.isKeyPressed(Keys.D)) { yaw++; } } it slowly swings from the left to the right. This approach worked for turning left and right for 2d games though. What am I doing wrong?

    Read the article

  • Computing a normal matrix in conjunction with gluLookAt

    - by Chris Smith
    I have a hand-rolled camera class that converts yaw, pitch, and roll angles into a forward, side, and up vector suitable for calling gluLookAt. Using this camera class I can modify the model-view matrix to move about the 3D world just fine. However, I am having trouble when using this camera class (and associated model-view matrix) when trying to perform directional lighting in my vertex shader. The problem is that the light direction, (0, 1, 0) for example, is relative to where the 'camera is looking' and not the actual world coordinates. (Or is this eye coordinates vs. model coordinates?) I would like the light direction to be unaffected by the camera's viewing direction. For example, when the camera is looking down the Z axis the ground is lit correctly. However, if I point the camera straight at the ground, then it goes dark. This is (I think) because the light direction is parallel with the camera's 'up' vector which is perpendicular with the ground's normal vector. I tried computing the normal matrix without taking the camera's model view into account, but then none of my objects were rotated correctly. Sorry if this sounds vague. I suspect there is a straight forward answer, but I'm not 100% clear on how the normal matrix should be used for transforming vertex normals in my vertex shader. For reference, here is pseudo code for my rendering loop: pMatrix = new Matrix(); pMatrix = makePerspective(...) mvMatrix = new Matrix() camera.apply(mvMatrix); // Calls gluLookAt // Move the object into position. mvMatrix.translatev(position); mvMatrix.rotatef(rotation.x, 1, 0, 0); mvMatrix.rotatef(rotation.y, 0, 1, 0); mvMatrix.rotatef(rotation.z, 0, 0, 1); var nMatrix = new Matrix(); nMatrix.set(mvMatrix.get().getInverse().getTranspose()); // Set vertex shader uniforms. gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, new Float32Array(pMatrix.getFlattened())); gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix.getFlattened())); gl.uniformMatrix4fv(shaderProgram.nMatrixUniform, false, new Float32Array(nMatrix.getFlattened())); // ... gl.drawElements(gl.TRIANGLES, this.vertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0); And the corresponding vertex shader: // Attributes attribute vec3 aVertexPosition; attribute vec4 aVertexColor; attribute vec3 aVertexNormal; // Uniforms uniform mat4 uMVMatrix; uniform mat4 uNMatrix; uniform mat4 uPMatrix; // Varyings varying vec4 vColor; // Constants const vec3 LIGHT_DIRECTION = vec3(0, 1, 0); // Opposite direction of photons. const vec4 AMBIENT_COLOR = vec4 (0.2, 0.2, 0.2, 1.0); float ComputeLighting() { vec4 transformedNormal = vec4(aVertexNormal.xyz, 1.0); transformedNormal = uNMatrix * transformedNormal; float base = dot(normalize(transformedNormal.xyz), normalize(LIGHT_DIRECTION)); return max(base, 0.0); } void main(void) { gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); float lightWeight = ComputeLighting(); vColor = vec4(aVertexColor.xyz * lightWeight, 1.0) + AMBIENT_COLOR; } Note that I am using WebGL, so if the anser is use glFixThisProblem(...) any pointers on how to re-implement that on WebGL if missing would be appreciated.

    Read the article

  • calculate camera up vector after glulookat()?

    - by carrots
    I'm just starting out teaching myself openGL and now adding openAL to the mix. I have some planets scattered around in 3D space and when I touch the screen, I'm assigning a sound to a random planet and then slowly and smoothly flying the "camera" over to look at it and listen to it. The animation/tweening part is working perfectly, but the openAL piece isn't quiet right. I move the camera around by doing a tiny translate() and gluLookAt() for every frame to keep things smooth (tweening the camera position and lookAt coords). The trouble seems to be with the stereo image I'm getting out of the headphones.. it seems like the left/right/up/down is mixed up sometimes after the camera rolls or spins. I am pretty sure the trouble is here: ALfloat listenerPos[]={camera->currentX,camera->currentY,camera->currentZ}; ALfloat listenerOri[]={camera->currentLookX, camera->currentLookY, camera->currentLookZ, 0.0,//Camera Up X <--- here 0.1,//Camera Up Y <--- here 0.0}//Camera Up Z <--- and here alListenerfv(AL_POSITION,listenerPos); alListenerfv(AL_ORIENTATION,listenerOri); I'm thinking I need to recompute the UP vector for the camera after each gluLookAt() to straighten out the audio positioning problem.. but after hours of googling and experimenting I'm stuck in math that suddenly got way over my head. 1) Am I right that I need to recalculate the up vector after each gluLookAt() i do? 2) If so, can someone please walk me though figuring out how to do that?

    Read the article

  • gluLookAt alternative doesn't work

    - by Brammie
    Hey guys. I'm trying to calculate a lookat matrix myself, instead of using gluLookAt(). My problem is that my matrix doesn't work. using the same parameters on gluLookAt does work however. my way of creating a lookat matrix: Vector3 Eye, At, Up; //these should be parameters =) Vector3 zaxis = At - Eye; zaxis.Normalize(); Vector3 xaxis = Vector3::Cross(Up, zaxis); xaxis.Normalize(); Vector3 yaxis = Vector3::Cross(zaxis, xaxis); yaxis.Normalize(); float r[16] = { xaxis.x, yaxis.x, zaxis.x, 0, xaxis.y, yaxis.y, zaxis.y, 0, xaxis.z, yaxis.z, zaxis.z, 0, 0, 0, 0, 1, }; Matrix Rotation; memcpy(Rotation.values, r, sizeof(r)); float t[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -Eye.x, -Eye.y, -Eye.z, 1, }; Matrix Translation; memcpy(Translation.values, t, sizeof(t)); View = Rotation * Translation; // i tried reversing this as well (translation*rotation) now, when i try to use this matrix be calling glMultMatrixf, nothing shows up in my engine, while using the same eye, lookat and up values on gluLookAt works perfect as i said before. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(View); the problem must be in somewhere in the code i posted here, i know the problem is not in my Vector3/Matrix classes, because they work fine when creating a projection matrix.

    Read the article

  • gluLookAt doesn't work

    - by Tyzak
    hi, i'm programming with opengl and i want to change the camera view: ... void RenderScene() //Zeichenfunktion { glClearColor( 1.0, 0.5, 0.0, 0 ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity (); //1.Form: glBegin( GL_POLYGON ); //polygone glColor3f( 1.0f, 0.0f, 0.0f ); //rot glVertex3f( -0.5, -0.5, -0.5 ); //unten links 3 =3 koords, f=float glColor3f( 0.0f, 0.0f, 1.0f ); //blau glVertex3f( 0.5, -0.5, -0.5 ); //unten rechts glVertex3f( 0.5, 0.5, -0.5 );//oben rechts glVertex3f( -0.5, 0.5, -0.5 );//oben links glEnd(); Wuerfel(0.7); //creates cube with length 0.7 gluLookAt ( 0., 0.3, 1.0, 0., 0.7, 0., 0., 1., 0.); glFlush(); //Buffer leeren } ... when i change the parameter of gluLookAt, nothing happens, what do i wrong? thanks

    Read the article

  • OpenGL gluLookAt issues

    - by Chris D
    I am trying to switch my space invaders game to a first person view, i.e. a view of the world from the ship. I am getting a bit confused about what point I should be looking at. I am currently using these parameters in gluLookAt: GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GLU.gluLookAt(ship3dPos.x, ship3dPos.y, ship3dPos.z,400.0f, 600.0f,-50.0f, 0.0f, 1.0f,-0.0f); Where ship3dPos is a Vector3f. I'm not sure what I'm supposed to set parameters 4,5 and 6 to, to get a view of the whole world(window is 800/600). I want to have a view of say 100.0 wide from the ships perspective, with this view moving along the x-axis as the player moves the ship. Thanks

    Read the article

  • Creating an OpenGL FPS camera: I have the position and orientation vectors, now what?

    - by Synthetix
    I have been struggling to create a first person camera in OpenGL ES 2.0 without using gluLookAt(). I grab the camera's orientation vectors (the way it's looking) from the current modelview matrix, and use that to calculate the new forward/backward (Z) translation value. I then calculate the strafe (X) value from the dot product of Z and Y (which is always 1.0). So, I have all the information I need to create a view matrix, but how do I do that without using gluLookAt? Almost all the examples I've seen use gluLookAt, but no such function exists in OpenGL ES 2.0. Besides, one of the moderators on cprogramming.com mentioned that gluLookAt is not appropriate for FPS cameras: http://cboard.cprogramming.com/game-programming/135390-how-properly-move-strafe-yaw-pitch-camera-opengl-glut-using-glulookat.html I am really confused by all the conflicting information I'm getting. I just want to create a first person camera that goes forward (W,S keys), side-to-side (A,D keys) and rotates around its center (Y axis only), Wolfenstein style. Any help on this would be much appreciated!

    Read the article

  • How can I get the camera to follow a moving object from behind in C++ and openGL [closed]

    - by user1324894
    I am trying to get the camera to follow an object that moves around my environment using the gluLookAt function. This is my code for the object moving in the direction that it faces: Xtri += -Vtri*cos((90+heading)*(PI/180.0f)); Ztri += Vtri*sin((90+heading)*(PI/180.0f)); I then render the object: glPushMatrix(); glTranslatef(Xtri,0,Ztri); glRotatef(heading,0,1,0); drawTriangle(); glPopMatrix(); All heading is is a spin variable so that if I press left or right it spins in that direction. When you press up on the arrows it moves forward and if you press down it moves backwards in the direction that it is facing. To try and get it so the camera follows I am using the gluLookAt function like this: gluLookAt(Xtri,0,(Ztri+20), Xtri,0,Ztri, 0,1,0); So that it follows the car from a distance and should follow it around. However, the object doesn't even move at all now all it can do is rotate still but not move forwards or backwards and when it spins it doesn't follow the spin instead it just watches it turn still fixed to the same position. Where is it that I am going wrong? UPDATE: I have updated the gluLookAt function so now it is: gluLookAt((Xtri+Vtri),0,((Ztri+20)), (Xtri+Vtri),0,(Ztri), 0,1,0); This seems to move the object around. I have a stationary terrain so I can see that the object is now moving and in the direction that it is facing. However, I want the camera to follow the object when it spins as well so it is always viewing the object from behind.

    Read the article

  • How do I position a 2D camera in OpenGL?

    - by Elfayer
    I can't understand how the camera is working. It's a 2D game, so I'm displaying a game map from (0, 0, 0) to (mapSizeX, 0, mapSizeY). I'm initializing the camera as follow : Camera::Camera(void) : position_(0.0f, 0.0f, 0.0f), rotation_(0.0f, 0.0f, -1.0f) {} void Camera::initialize(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glTranslatef(position_.x, position_.y, position_.z); gluPerspective(70.0f, 800.0f/600.0f, 1.0f, 10000.0f); gluLookAt(0.0f, 6000.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); } So the camera is looking down. I currently see the up right border of the map in the center of my window and the map expand to the down left border of my window. I would like to center the map. The logical thing to do should be to move the camera to eyeX = mapSizeX / 2 and the same for z. My map has 10 x 10 cases with CASE = 400, so I should have : gluLookAt((10 / 2) * CASE /* = 2000 */, 6000.0f, (10 / 2) * CASE /* = 2000 */, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); But that doesn't move the camera, but seems to rotate it. Am I doing something wrong? EDIT : I tried that: gluLookAt(2000.0f, 6000.0f, 0.0f, 2000.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); Which correctly moves the map in the middle of the window in width. But I can't move if correctly in height. It always returns the axis Z. When I go up, It goes down and the same for right and left. I don't see the map anymore when I do : gluLookAt(2000.0f, 6000.0f, 2000.0f, 2000.0f, 0.0f, 2000.0f, 0.0f, 1.0f, 0.0f);

    Read the article

  • Display object in just a certain viewport

    - by PSilo
    Hi I got 4 viewports and one large that I can switch between now I got an object namely the camera and the cameras target position that I show with rendering a sphere at those locations. I want to show the cameras position in 3 of my viewports but not in the last which is the camera display but at the moment I got an all or nothing scenario. void display(int what) { if(what==5){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); camControll();} if(what==1){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(75,15,-5,0,5,-5,0,1,0);} if(what==2){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,110,0,0,0,0,1,0,0);} if(what==3){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, float(320) / float(240), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); camControll();} if(what==4){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(185,75,25,0,28,0,0,1,0);} //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); ////gluLookAt(cos(shared.time) * shared.distance, 10, sin(shared.time) * shared.distance, 0, 0, 0, 0, 1, 0); ////ca.orbitYaw(0.05); //ca.lookAt(); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); drawScene(); // scene that all views should render drawCamera(); / camera position that only certain views should render glutSwapBuffers(); } I'm thinking that perhaps I could do one sweep for first the 3 viewports and then call glutSwapBuffers() and then do the other viewport without the camera position but some stuttering I previously had was traced to glutSwapBuffers() being called for each viewport so I guess there has to be another way only that I cant figure it out.

    Read the article

  • Multiple viewport problem

    - by PSilo
    I'm setting up so I can switch between either one or four viewports but I got some trouble. In my bottom right viewport I got camera view, the same camera that I can switch to full view on. The other three viewports are working with fixed locations but the bottom right viewport is compressed on the y scale and half of the picture on the x scale is missing. void display(int what) { if(what==5){glViewport(0, 0, w, h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ca.lookAt();} if(what==1){glViewport(0, 0, w/2, h/2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(75,15,-5,0,5,-5,0,1,0);} if(what==2){glViewport(w/2, h/2, w, h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,110,0,20,0,20,1,0,0);} if(what==3){glViewport(w/2, 0, w, h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, float(320) / float(240), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ca.lookAt();} if(what==4){glViewport(0, h/2, w/2, h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(185,75,25,0,28,0,0,1,0);} //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); ////gluLookAt(cos(shared.time) * shared.distance, 10, sin(shared.time) * shared.distance, 0, 0, 0, 0, 1, 0); // Roterar kameran kring origo genom att skapa en ny vymatris varje bildruta ////ca.orbitYaw(0.05); //ca.lookAt(); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); drawScene(); drawCamera(); glutSwapBuffers(); } void viewport(){ glEnable(GL_SCISSOR_TEST); if(!divided_view_port) { glViewport(0, 0, w, h); glScissor(0,0,640,480); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 100.0f); display(5); } else { ////////////////////// bottom left - working glViewport(0, 0, w/2, h/2); glScissor(0,0,w/2,h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(1); ////////////////////// ////////////////////// top right - working glViewport(w/2, h/2, w, h); glScissor(w/2,h/2,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(2); ////////////////////// ////////////////////// bottom right -working glViewport(w/2, 0, w, h/2); glScissor(w/2,0,w,h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(3); //////////////////////// ////////////////////////// top left glViewport(0, h/2, w/2, h); glScissor(0,h/2,w/2,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(4); /////////////////////////// } glDisable(GL_SCISSOR_TEST); glMatrixMode(GL_MODELVIEW); }

    Read the article

  • JOGL hardware based shadow mapping - computing the texture matrix

    - by axel22
    I am implementing hardware shadow mapping as described here. I've rendered the scene successfully from the light POV, and loaded the depth buffer of the scene into a texture. This texture has correctly been loaded - I check this by rendering a small thumbnail, as you can see in the screenshot below, upper left corner. The depth of the scene appears to be correct - objects further away are darker, and that are closer to the light are lighter. However, I run into trouble while rendering the scene from the camera's point of view using the depth texture - the texture on the polygons in the scene is rendered in a weird, nondeterministic fashion, as shown in the screenshot. I believe I am making an error while computing the texture transformation matrix, but I am unsure where exactly. Since I have no matrix utilities in JOGL other then the gl[Load|Mult]Matrix procedures, I multiply the matrices using them, like this: void calcTextureMatrix() { glPushMatrix(); glLoadIdentity(); glLoadMatrixf(biasmatrix, 0); glMultMatrixf(lightprojmatrix, 0); glMultMatrixf(lightviewmatrix, 0); glGetFloatv(GL_MODELVIEW_MATRIX, shadowtexmatrix, 0); glPopMatrix(); } I obtained these matrices by using the glOrtho and gluLookAt procedures: glLoadIdentity() val wdt = width / 45 val hgt = height / 45 glOrtho(wdt, -wdt, -hgt, hgt, -45.0, 45.0) glGetFloatv(GL_MODELVIEW_MATRIX, lightprojmatrix, 0) glLoadIdentity() glu.gluLookAt( xlook + lightpos._1, ylook + lightpos._2, lightpos._3, xlook, ylook, 0.0f, 0.f, 0.f, 1.0f) glGetFloatv(GL_MODELVIEW_MATRIX, lightviewmatrix, 0) My bias matrix is: float[] biasmatrix = new float[16] { 0.5f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.f, 0.5f, 0.5f, 0.5f, 1.f } After applying the camera projection and view matrices, I do: glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR) glTexGenfv(GL_S, GL_EYE_PLANE, shadowtexmatrix, 0) glEnable(GL_TEXTURE_GEN_S) for each component. Does anybody know why the texture is not being rendered correctly? Thank you.

    Read the article

  • Noob question: Draw a quad parallel to the view.

    - by Jack
    Hi all, ok what I want to do is to draw a quad in the scene that lays on a plane parallel to the view. So it should appear flat. More in particular, I think I didn't get very well how the mechanism of gluLookAt works in comparison with the functions glTranslate and glRotate: If I position the view "manually" using the functions glTranslate and glRotate whenever I draw an object its position is relative to the current view. And I understand that this is due to the transformation matrix in the stack. However when I use the gluLookAt that should automatically set the view, the coordinates of the object I want to draw must be "absolute" to show it properly. Thanks in advance.

    Read the article

  • Axis Aligned Billboard: how to make the object look at camera

    - by user19787
    I am trying to make an Axis Aligned Billboard with Pyglet. I have looked at several tutorials, but they only show me how to get the Up,Right,and Look vectors. So far this is what I have: target = cam.pos look = norm( target - billboard.pos ) right = norm( Vector3(0,1,0)*look ) up = look*right gluLookAt( look.x, look.y, look.z, self.pos.x, self.pos.y, self.pos.z, up.x, up.y, up.z ) This does nothing for me visibly. Any idea what I'm doing wrong?

    Read the article

  • Camera rotation - First Person Camera using GLM

    - by tempvar
    I've just switched from deprecated opengl functions to using shaders and GLM math library and i'm having a few problems setting up my camera rotations (first person camera). I'll show what i've got setup so far. I'm setting up my ViewMatrix using the glm::lookAt function which takes an eye position, target and up vector // arbitrary pos and target values pos = glm::vec3(0.0f, 0.0f, 10.0f); target = glm::vec3(0.0f, 0.0f, 0.0f); up = glm::vec3(0.0f, 1.0f, 0.0f); m_view = glm::lookAt(pos, target, up); i'm using glm::perspective for my projection and the model matrix is just identity m_projection = glm::perspective(m_fov, m_aspectRatio, m_near, m_far); model = glm::mat4(1.0); I send the MVP matrix to my shader to multiply the vertex position glm::mat4 MVP = camera->getProjection() * camera->getView() * model; // in shader gl_Position = MVP * vec4(vertexPos, 1.0); My camera class has standard rotate and translate functions which call glm::rotate and glm::translate respectively void camera::rotate(float amount, glm::vec3 axis) { m_view = glm::rotate(m_view, amount, axis); } void camera::translate(glm::vec3 dir) { m_view = glm::translate(m_view, dir); } and i usually just use the mouse delta position as the amount for rotation Now normally in my previous opengl applications i'd just setup the yaw and pitch angles and have a sin and cos to change the direction vector using (gluLookAt) but i'd like to be able to do this using GLM and matrices. So at the moment i have my camera set 10 units away from the origin facing that direction. I can see my geometry fine, it renders perfectly. When i use my rotation function... camera->rotate(mouseDeltaX, glm::vec3(0, 1, 0)); What i want is for me to look to the right and left (like i would with manipulating the lookAt vector with gluLookAt) but what's happening is It just rotates the model i'm looking at around the origin, like im just doing a full circle around it. Because i've translated my view matrix, shouldn't i need to translate it to the centre, do the rotation then translate back away for it to be rotating around the origin? Also, i've tried using the rotate function around the x axis to get pitch working, but as soon as i rotate the model about 90 degrees, it starts to roll instead of pitch (gimbal lock?). Thanks for your help guys, and if i've not explained it well, basically i'm trying to get a first person camera working with matrix multiplication and rotating my view matrix is just rotating the model around the origin.

    Read the article

  • How do I implement camera axis aligned billboards?

    - by user19787
    I am trying to make an axis-aligned billboard with Pyglet. I have looked at several tutorials, but they only show me how to get the up, right, and look vectors. So far this is what I have: target = cam.pos look = norm(target - billboard.pos) right = norm(Vector3(0,1,0) * look) up = look * right gluLookAt( look.x, look.y, look.z, self.pos.x, self.pos.y, self.pos.z, up.x, up.y, up.z ) This does nothing for me visibly. Any idea what I'm doing wrong?

    Read the article

  • How to rotate camera centered around the camera's position?

    - by tnutty
    Currently I am using gluLook at like so: gluLookAt(position.x, position.y, position.z, viewPoint.x, viewPoint.y, viewPoint.z, upVector.x, upVector.y, upVector.z); with the above, don't know if you need more information, how could I change it so that the camera acts like its rotating around itself, instead rotating around its viewpoint. You can see the current code at https://github.com/dchhetri/OpenGL-City/blob/master/opengl_camera.cpp, that class was adapted from codecolony.com.

    Read the article

  • Draw camera position in specific view port.

    - by snackbar
    Most of this code should be fairly self explanatory. I got an display function and my view port function. There are two modes which is 4 small view ports in the window or one large. I got one camera which can be moved and if in 4 view port mode just 3 fixed angles. The thing is I want the free moving cameras position to be displayed in the 3 other view ports. I tried doing it by drawing spheres using opengl but the problem is that then the position gets draw in the free roaming camera too as it shows the same scene. It doesn't have to be a sphere, just something simple that represents the cameras spacial position in these three other views. Drawing the scene once with camera object showing for the three viewports, render to texture. Clear and draw scene without camera object render to texture and then stitch these together before actually drawing the scene seems like a lot o work for something that should be easy. void display(int what) { if(what==5){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); camControll();} if(what==1){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(75,15,-5,0,5,-5,0,1,0);} if(what==2){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,110,0,0,0,0,1,0,0);} if(what==3){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, float(320) / float(240), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); camControll();} if(what==4){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(185,75,25,0,28,0,0,1,0);} glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); drawScene(); drawCamera(); glutSwapBuffers(); } void viewport(){ glEnable(GL_SCISSOR_TEST); if(!divided_view_port) { glViewport(0, 0, w, h); glScissor(0,0,640,480); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 100.0f); display(5); } else { ////////////////////// bottom left - working glViewport(0, 0, w/2, h/2); glScissor(0,0,w/2,h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(1); ////////////////////// ////////////////////// top right - working glViewport(w/2, h/2, w/2, h/2); glScissor(w/2,h/2,w/2,h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(2); ////////////////////// ////////////////////// bottom right -working glViewport(w/2, 0, w/2, h/2); glScissor(w/2,0,w/2,h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(3); //////////////////////// ////////////////////////// top left glViewport(0, h/2, w/2, h/2); glScissor(0,h/2,w/2,h/2); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, w / h, 0.1f, 300.0f); display(4); /////////////////////////// } glDisable(GL_SCISSOR_TEST); glMatrixMode(GL_MODELVIEW); }

    Read the article

  • How to setup OpenGL camera for a racing game

    - by vian
    I need the view to show the road polygon (a rectangle 3.f * 100.f) with a vanishing point for a road being at 3/4 height of the viewport and the nearest road edge as a viewport's bottom side. See Crazy Taxi game for an example of what I wish to do. I'm using iPhone SDK 3.1.2 default OpenGL ES project template. I setup the projection matrix as follows: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustumf(-2.25f, 2.25f, -1.5f, 1.5f, 0.1f, 1000.0f); Then I use glRotatef to adjust for landscape mode and setup camera. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(-90, 0.0f, 0.0f, 1.0f); const float cameraAngle = 45.0f * M_PI / 180.0f; gluLookAt(0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 100.0f, 0.0f, cos(cameraAngle), sin(cameraAngle)); My road polygon triangle strip is like this: static const GLfloat roadVertices[] = { -1.5f, 0.0f, 0.0f, 1.5f, 0.0f, 0.0f, -1.5f, 0.0f, 100.0f, 1.5f, 0.0f, 100.0f, }; And I can't seem to find the right parameters for gluLookAt. My vanishing point is always at the center of the screen.

    Read the article

  • switch from glOrtho to gluPerspective

    - by Knitex
    I have a car draw at (0,0) and some obstacles set up but right now my main concern is switching from glPerspective to glOrtho and vice-versa. All that i get when i switch from perspective to ortho is a black screen. void myinit(){ glClearColor(0.0,0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60,ww/wh,1,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(-5,5,3,backcarx,topcarx,0,0,0,1); } void menu(int id){ /*menu selects if you want to view it in ortho or perspective*/ if(id == 1){ glClear(GL_DEPTH_BUFFER_BIT); glViewport(0,0,ww,wh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2,100,-2,100,-1,1); glMatrixMode(GL_MODELVIEW); glutPostRedisplay(); } if(id == 2){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60,ww/wh,1,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); viewx = backcarx - 10; viewy = backcary - 10; gluLookAt(viewx,viewy,viewz,backcarx,topcarx,0,0,0,1); } } i've tried using the clear depth buffer and still doesnt work.

    Read the article

  • View matrix in opengl

    - by user5584
    Hi! Sorry for my clumsy question. But I don't know where I am wrong at creating view matrix. I have the following code: createMatrix(vec4f(xAxis.x, xAxis.y, xAxis.z, dot(xAxis,eye)), vec4f( yAxis.x_, yAxis.y_, yAxis.z_, dot(yAxis,eye)), vec4f(-zAxis.x_, -zAxis.y_, -zAxis.z_, -dot(zAxis,eye)), vec4f(0, 0, 0, 1)); //column1, column2,... I have tried to transpose it, but with no success. I have also tried to use gluLookAt(...) with success. At the reference page, I watched the remarks about the to-be-created matrix, and it seems the same as mine. Where I am wrong?

    Read the article

  • Rotate a particle system

    - by Blueski
    Languages / Libraries in use: C++, OpenGL, GLUT Okay, here's the deal. I've got a particle system which shoots out alpha blended textures to produce a flame. The system only keeps track of very basic things such as, time alive, life, xyz and spread. The direction in which the flames are currently moving in is purely based on other things which are going on in my code ( I assume ). My goal however, is to attach the flame to the camera (DONE) and have the flame pointing in the direction my camera is facing (NOT WORKING). I've tried glRotate for both x,y,z and I can't get it to work properly. I'm currently using gluLookAt to move the camera, and get the flame to follow the XYZ of the camera by calling glTranslatef(camX, camY - offset, camZ); Any suggestions on how I can rotate the direction of the flame with the camera would be greatly appreciated. Heres an image of what I've got: http://i.imgur.com/YhV4w.png Notes: Crosshair depicts where camera is facing if I turn the camera, flame doesn't follow the crosshair Also asked here: http://stackoverflow.com/questions/9560396/rotate-a-particle-system but was referred here

    Read the article

1 2  | Next Page >