Thread: OpenGL Prob

  1. #1
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949

    OpenGL Prob

    I'm trying to adapt some code from a site to my code, to see how this works, but it isnt working. The code is supposed to control the view with the screen, and move the cursor back to the middle. It moves the cursor to the middle, but the view vector stays the same. When compiled, it only comes up with two warnings:

    test.cpp 311: angleZ is assigned a value that is never used in function SetViewByMouse.
    test.cpp 310: angleY is assigned a value that is never used in function SetViewByMouse.

    These are the functions to move the mouse:
    Code:
    void SetViewByMouse() {
    	POINT mousePos;
    Vector3D m_vPosition(posx, posy, posz);
    	int middleX = 400;
    	int middleY = 300;
    	float angleY = 0.0f; //line 310
    	float angleZ = 0.0f; //line 311
    	float currentRotX = 0.0f;
    	GetCursorPos(&mousePos);						
    	if( (mousePos.x == middleX) && (mousePos.y == middleY) ) return;
    	SetCursorPos(middleX, middleY);
    	angleY = (float)( (middleX - mousePos.x) ) / 1000.0f;		
    	angleZ = (float)( (middleY - mousePos.y) ) / 1000.0f;
    	static float lastRotX = 0.0f; 
     	lastRotX = currentRotX;
    	currentRotX += angleZ;
    	if(currentRotX > 1.0f) {
    		currentRotX = 1.0f;
    		if(lastRotX != 1.0f) {
    			Vector3D vAxis = m_vUpVector.crossProduct(m_vView - m_vPosition);
    			vAxis = vAxis.normalize();
    			RotateView( 1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z);
    		}
    	} else if(currentRotX < -1.0f) {
    		currentRotX = -1.0f;
    		if(lastRotX != -1.0f) {
    			Vector3D vAxis = m_vUpVector.crossProduct(m_vView - m_vPosition);
    			vAxis = vAxis.normalize();
    			RotateView( -1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z);
    		}
    	} else {
    		Vector3D vAxis = m_vUpVector.crossProduct(m_vView - m_vPosition);
    		vAxis = vAxis.normalize();
    		RotateView(angleZ, vAxis.x, vAxis.y, vAxis.z);
    	}
    	RotateView(angleY, 0, 1, 0);
    }
    
    void RotateView(float angle, float x, float y, float z) {
    Vector3D m_vPosition(posx, posy, posz);
    	Vector3D vNewView;
    	Vector3D vView = m_vView - m_vPosition;		
    	float cosTheta = (float)cos(angle);
    	float sinTheta = (float)sin(angle);
    	vNewView.x  = (cosTheta + (1 - cosTheta) * x * x)		* vView.x;
    	vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta)	* vView.y;
    	vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta)	* vView.z;
    	vNewView.y  = ((1 - cosTheta) * x * y + z * sinTheta)	* vView.x;
    	vNewView.y += (cosTheta + (1 - cosTheta) * y * y)		* vView.y;
    	vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta)	* vView.z;
    	vNewView.z  = ((1 - cosTheta) * x * z - y * sinTheta)	* vView.x;
    	vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta)	* vView.y;
    	vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;
    	m_vView = m_vPosition + vNewView;
    }
    Hope you can help, thanks !
    Do not make direct eye contact with me.

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Here is the whole file, just in case:
    Do not make direct eye contact with me.

  3. #3
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    OK....can anyone at least explain why angleX / Y aren't seen by the compiler? Thanks !
    Do not make direct eye contact with me.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well the reason for the warnings is pretty obvious, but that wont help with the wider problem of it not working.

    test.cpp 310: angleY is assigned a value that is never used in function SetViewByMouse.
    float angleY = 0.0f; //line 310

    and 6 lines later, without ever having used angleY
    angleY = (float)( (middleX - mousePos.x) ) / 1000.0f;
    You can safely delete the initialisers on lines 310, 311
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Thanks Salem. Heres my updated version (changed a few things):
    Last edited by Lurker; 12-13-2003 at 04:45 PM.
    Do not make direct eye contact with me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL prob
    By HQSneaker in forum Game Programming
    Replies: 18
    Last Post: 06-22-2006, 12:55 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. Mouse 'control' prob in OpenGL
    By gazsux in forum Game Programming
    Replies: 5
    Last Post: 04-17-2003, 10:00 AM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  5. FPS Counter Prob in OpenGL
    By brandonp in forum Game Programming
    Replies: 1
    Last Post: 07-16-2002, 02:49 PM