# Steve-B

Member

114

150 Neutral

• Rank
Member
1. ## Camera Rotation using gluLookAt

Ok, I've managed to get it working now. Tried to delete this thread but looks like I left it too long. Moderators?
2. ## Camera Rotation using gluLookAt

Hi. I am setting up a camera using gluLookAt and I'm not sure how to do rotations. I have the first camera lesson from the Game Tutorials site so I can make the camera move forwards and backwards but how do you make it rotate? I've been told lesson 2 and 3 show how to achieve this. Would anyone be willing to e-mail me those tutorials or give some advice on what do to. Thanks.
3. ## Lighting: Object Space vs Eye Space

Here is the code that I'm using. Mhamlin: If you look at the code you will see the lines which perform the modelview inverse calculations. They are commented out cos of the problems I've been having. I think I may have to send the camera view vector to the cg function as well as the eye position. Maybe?? Output VertexShader(Input IN, Lighting LIGHT, Surfaces MATERIAL, uniform float4 eyePosition, uniform float3x3 modelView, uniform float4x4 modelViewInverse, uniform float3x3 modelViewInvTrans, uniform float4x4 modelViewProj) { Output OUT; // Here we convert the output vertex from object-space to clip-space OUT.position = mul(modelViewProj, IN.position); // Set the material ambient property to 100% by default (temporary??) MATERIAL.Ka = (1.0, 1.0, 1.0); // *** NEW EYE-SPACE TRANSFORMATIONS *** float3 P = IN.position.xyz; float3 N = IN.normal.xyz; // Convert the vertex position from object-space to eye-space /* float3 P = mul(modelView, IN.position.xyz); normalize(P); // Convert the vertex normal using the inverse transpose of the modelview matrix float3 N = mul(modelViewInvTrans, IN.normal); normalize(N); */ // Multiply the light position by the inverse modelview matrix // float3 L = mul(modelViewInverse, LIGHT.position - P); float3 L = normalize(LIGHT.position.xyz - P); // *** NEW EYE-SPACE TRANSFORMATIONS *** // Calculate the attenuation float attenuation = Attenuation(P, LIGHT); // Compute the emmisive term float3 emmisive = MATERIAL.Ke; // Compute the ambient term float3 ambient = MATERIAL.Ka * LIGHT.ambient.xyz; // Compute the diffuse term float diffuseLight = max(dot(N, L), 0); float3 diffuse = MATERIAL.Kd * LIGHT.colour.xyz * diffuseLight * attenuation; // Compute the specular term float3 V = eyePosition.xyz; float3 H = normalize(L + V); float specularLight = pow(max(dot(N, H), 0), MATERIAL.shininess); if(diffuseLight <= 0) specularLight = 0; float3 specular = MATERIAL.Ks * LIGHT.colour.xyz * specularLight * attenuation; // Compute the final vertex colour float3 lighting = (emmisive + ambient + diffuse + specular); // Pass the texture in Texture Unit 0 to the fragment program OUT.texCoord = IN.texCoord; // Pass the current colour to the fragment program OUT.colour.xyz = IN.colour.xyz * lighting; OUT.colour.w = IN.colour.w; return OUT; }
4. ## OpenGL Lighting: Object Space vs Eye Space

I'm playing about with lighting through Cg. I have setup a basic lighting algorithm which calculates diffuse,specular, global ambient etc. I also have some nice looking distance attenuation going on. It is using the same basic model as OpenGL. I am lighting all my objects in their local object-space and it's been working great... until they move. Then I found that the lighting still think they're in their original location and they end being completely unlit. Not a good thing. How can I solve this?? Is this a limit with lighting in object space? Do I need to perform my lighting in eye-space instead?? Sre there any tutorials on lighting in eye space?? How do you do this because I am unable to get the same visual effect like I had in my object-space calculations. The lighting keeps flying off everytime I rotate the camera and it only lights the scenery properly when I'm looking directly down the negative Z axis. Looking down the positive Z axis causes the scene to go pitch black. This may be linked to the light flying off when the camera is rotated. Anyone got any advice?? :) Cheers, Steve
5. ## How on earth do you load a custom cursor??

Thanks for the help. Looks like I'll have to take the OpenGL route as I still can't get the pointer working through the Windows functions. Not sure what I'm doing wrong. I've taken the advice 'lack' but still it doesn't work. I'll use the OpenGL method. Cheers.
6. ## How to control distance attenuation?

Hi I'm playing with lighting at the moment and I ahve written my lighting code as part of a Cg script file. It works great but now I've added distance attenuation and I'm not getting the results I'm looking for. What I want to know is how do the following constants affect the final image? GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION What I'm trying to achieve is a similar effect to fogging. I want polygons at a certain distance to be completely blacked out. At the moment it looks pretty good but I want the distance the light extends to be much shorter. Anyone got any advice on this subject?? STeve
7. ## How on earth do you load a custom cursor??

I'm already using the LoadCursor function. I'm using it in the same way that I use the LoadIcon function. I use it like this: winclass.hIcon = LoadIcon(NULL, "IDI_WATERDEEP"); winclass.hCursor = LoadCursor(NULL, "IDC_WATERDEEP"); Using this code the icon works great but the cursor just shows up as the standard windows hour glass cursor.
8. ## How on earth do you load a custom cursor??

Hi guys & gals I know this isn't strictly an OpenGL issue but it's still games related. Basically I'm having trouble adding a custom mouse pointer to my OpenGL game. I don't want the standard windows mouse pointer as it just looks naff in a game. Plus I want the cursor to change when the mouse is positioned over certain objects in the game. I'll figure that part out myself though. Anyway I have created the cursor in Visual Studio 6 in the same way I created an icon for the program. I used the usual resource file creation method that worked for my program icon. Unfortunately when the program loads the mouse pointer just shows up as the hourglass cursor. I'm loading the cursor as a resource and I can't figure out why this doesn't work. Is there anything special you have to do for cursors? Do they have to be a certain size or number of colours? Are there any tutorials on the net?? Cheers, Steve
9. ## How to control an object in 3D space

Ok, I guess I'll post some code: The problem I have is when i translate (from the origin) along an axis and then try to rotate around the objects centre of gravity. Instead the object rotates in a big circle around the centre of the world coordinate system. I remember having a similar problem ages ago but I can't remember how I fixed it. This is my main render function: // This is the main drawing function which is called every frame... void Render(CLOCK *time) { // First we need to clear the screen and the depth buffer... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset the Modelview Matrix (start with a nice clean slate) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /****** STAGE 1: CALCULATE THE VIEWING TRANSFORMATION! ******/ glTranslatef(0.0f, 0.0f, -15.0f); /****** STAGE 2: CALCULATE THE MODELLING TRANSFORMATION! ******/ Draw3D(); Draw2D(time); /****** STAGE 3: FLUSH THE OPENGL GRAPHICS PIPELINE ******/ glFlush(); } This is the Draw3D() function: void Draw3D(void) { glDisable(GL_CULL_FACE); glPushMatrix(); QuatRotation(); // Perform object rotation // We need to find the direction vector from the object position to it's facing directon // To do this we take the end point (N) and subtract the starting point (C). //CVector N = camera_quat.GetAxis(); //CVector Delta = (N - position); // Calculate our new direction vector //position += (Delta * 0.01f); // Increase the camera position in the direction we're facing // N += (Delta * speed); // Increase the view position in the direction we're facing // First we translate into position... glTranslatef(position.x, position.y, position.z); // Here we pass the 'modelview projection matrix' to our Cg program cgGLSetStateMatrixParameter(modelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); // Next we enable our Cg vertex profile and bind the vertex program cgGLEnableProfile(shader->vertexProfile); cgGLBindProgram(basicProgram); // Next we enable our Cg fragment profile and bind the fragment program cgGLEnableProfile(shader->fragmentProfile); cgGLBindProgram(fragmentProgram); // Finally we display the light object glBegin(GL_QUADS); /*glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, -1.0f); // LEFT glVertex3f(-0.5f, 1.0f, 1.0f); glVertex3f(-0.5f, -1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, -1.0f); // RIGHT //glColor3f(red, green, blue); glVertex3f(0.5f, -1.0f, 1.0f); glVertex3f(0.5f, 1.0f, 1.0f);*/ glColor3f(red, green, blue); glVertex3f(0.5f, 0.8f, -1.0f); glVertex3f(-0.5f, 0.8f, -1.0f); // TOP glVertex3f(-0.5f, -0.8f, -1.0f); glVertex3f(0.5f, -0.8f, -1.0f); /*glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, -1.0f); // BOTTOM //glColor3f(red, green, blue); glVertex3f(0.5f, -1.0f, 1.0f); glVertex3f(-0.5f, -1.0f, 1.0f);*/ glEnd(); // Disable the vertex/fragment profiles so we can render the point light using ordinary T&L cgGLDisableProfile(shader->fragmentProfile); cgGLDisableProfile(shader->vertexProfile); glPopMatrix(); glEnable(GL_CULL_FACE); }
10. ## How to control an object in 3D space

Hi I think this is a basic question but here goes. I'm trying to move a simple object around the screen but I want it to move according to it's own axis. The object is a little car object and I want it to be able to turn and then translate in the direction it's facing. I believe I need to use vectors for this so I have written my own vector class but I'm not really sure how to use it to achieve the effect I'm looking for. Do I have to use the objects local coordinate system or something? Steve
11. ## Very strange problem which seems related to DirectInput...

This is what my main loop looks like. It constantly reads the input devices every frame and saves the information in the structures/array. It all seems fine to me but I'm sure something must be wrong somewhere. If not then I guess the crash must be down to a bad graphics driver. Note that the devices do actually work and I can successfully read data from the input devices. Also I have put these three stuctures/array as externs in my Main.h header file so they are accessible to other files within my program. This couldn't be the cause of the problem could it? Anyway here is the code for my program main loop: Hope someone can help, Steve-B UCHAR key_state[256]; // Create our array for storing the keyboard state DIMOUSESTATE2 mouse_state; // Create a pointer to the mouse state structure DIJOYSTATE2 joy_state; // Create a pointer to the joystick state structure // THE MAIN WINDOWS EVENT LOOP while(TRUE) { if(!r3d->ProcessMessages()) // Quit if the function returns FALSE break; dinput->UpdateKeyboard(key_state); // Check the keyboard for key presses dinput->UpdateMouse(&mouse_state); // Check the mouse for clicks/movements dinput->UpdateJoystick(&joy_state); // Check the joystick for any actions Update(timer->elapsed); // Update the display Render(timer->clock); // Render the display SwapBuffers(r3d->hDC); // Swap the buffers (Double Buffering) timer->UpdateTimer(); // Update the current timer (measured in seconds) timer->UpdateFrame(); // Update the frame rate (measured in frames per second) }
12. ## Very strange problem which seems related to DirectInput...

Hi guys Ever since I added DirectInput code to my program (about a year ago) every now and again my program crashes, seemingly randomly. The error I recieved was the standard XP 'Please tell Microsoft about this problem' message. If I click on debug I am given a memory location and that a 'memory write error occured'. The crash can occur after a minute or two and I have successfully ran my program for hours before it crashes with the same problem. I'd like to know if there is something you guys can see that I'm doing wrong in my DirectInput code. I've done some testing and it doesn't appear to crash when I remove the DirectInput function calls. I think I might have tracked the bug down to the UpdateKeyboard function but I'm not 100% on this. UpdateMouse and UpdateJoystick seem to be fairly stable. Here is my the code in DirectInput.cpp: // Call this function in WinMain to update the keyboard state in real-time bool DirectInput::UpdateKeyboard(LPVOID keyboard_state) { hr = lpdiKeyboard->GetDeviceState(sizeof(UCHAR[256]), keyboard_state); if(FAILED(hr)) { if(hr == DIERR_INPUTLOST) { // The device has been lost so we attempt to reacquire it... hr = lpdiKeyboard->Acquire(); if(FAILED(hr)) return FALSE; } } return TRUE; } // Call this function in WinMain to update the mouse state in real-time bool DirectInput::UpdateMouse(DIMOUSESTATE2 *mouse_state) { hr = lpdiMouse->GetDeviceState(sizeof(DIMOUSESTATE2), mouse_state); if(FAILED(hr)) { if(hr == DIERR_INPUTLOST) { // The device has been lost so we attempt to reacquire it... hr = lpdiMouse->Acquire(); if(FAILED(hr)) return FALSE; } } return TRUE; } // Call this function in WinMain to update the joystick state in real-time bool DirectInput::UpdateJoystick(DIJOYSTATE2 *joystick_state) { if(joystick_found) { hr = lpdiJoystick->Poll(); // Poll is only required for joysticks! if(FAILED(hr)) { if(hr == DIERR_INPUTLOST) { // The device has been lost so we attempt to reacquire it... hr = lpdiJoystick->Acquire(); if(FAILED(hr)) return FALSE; } } hr = lpdiJoystick->GetDeviceState(sizeof(DIJOYSTATE2), joystick_state); if(FAILED(hr)) return FALSE; } return TRUE; }
13. ## Texture mapping a Lightwave 3D object...

Hi My lightwave object loader is almost finished apart from one little problem. I can't find any texture mapping coordinates in the model files. I'm using Lightwave 5 and the objects it produces don't seem to contain any texture coordinates. So how on earth am I supposed to texture an object with no coordinates??? Do I have to calculate them myself??? Anyone got any experience of writing a Lightwave object loader and come across this problem? Steve
14. ## Display Lists (advanced question)

Hi Thanks for your replies. I might give the glDrawElements a bit of investigation and see what happens when I use that. I'll just say that my program would not instantly crash. It would run for between 30 minutes to sometimes 3 or more hours before crashing with a memory error message. Well my code is now pretty stable (but that's without display lists). It also seems to be more stable since I changed all the objects in my demo to use pointers... For example I have a vector class which I used to create an object with. Vector camera; Set the code running and went off to work. By the time I got home (9 hours later) it had crashed. So I changed that new addition to my program to this: Vector *camera; Initialise the camera (allocate RAM for it) in my setup function and the program didn't crash and ran for over 9 hours. Maybe I'm barking up the wrong tree but this sort of thing affects my engine. I'm not sure why though. I didn't think there was anything wrong with using the first method. Which method does everyone else use for adding objects to your demos?? Steve-B
15. ## Display Lists (advanced question)

Hi All This is a bit of an advanced question about display lists. I was contemplating whether to post this on the opengl.org advanced forum or here. I couldn't be arsed to setup an account on OpenGL.org so here we are. lol. Anyway the problem is that I have created a class that loads a Lightwave model. The model polygon and vertex data is stored in pointers within the class. Now I then load the model into my opengl app by created a pointer to the class: Lightwave *model = NULL; Then I initialise the model as normal and load the object into the memory. Now here is where display lists come in. The data is then passed to a display list using the array version of the opengl commands. I then delete the model data freeing up the memory it used and the model is display using the display list and it works fine. The problem is my program sometimes crashes and it is very annoying. The only time it doesn't crash is when I remove the display list code. The error message I recieve is always an unreferenced memory error. Is there something I should know about display lists that is going on behind the scenes?? Steve