OpenGL Camera

This is a discussion on OpenGL Camera within the Game Programming forums, part of the General Programming Boards category; I wrote this, it approaches 100% accuracy as you increase the number of iterations. 4 iterations are typically required to ...

  1. #16
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    square root

    I wrote this, it approaches 100% accuracy as you increase the number of iterations. 4 iterations are typically required to get an acceptable answer. it does it by calculating tangent lines and where they intersect the x axis (they get closer and closer to the number's root as you keep intersecting with the x axis). im just happy as a puffer fish that the goddam thing actually seems to work accurately with only 4 iterations.

    Code:
    /*
    	-Finds the root of x^2 - r
    	-Need slope(m), need b, need curr x, need curry 
    	-FIXME: add tolerance variable? i.e answer must be within TOLERANCE from real root 
    */
    float	IterSqrtf(float	r, int numtries)
    {
    	float	m(0.0f);
    	float	b(0.0f);
    	float	currx=r;
    	float	curry(0.0f);
    	float	root(0.0f); //this is what gets returned 
    
    	while(numtries--)
    	{
    		curry = (currx*currx) - r; //y1
    		//Check to see if curry is < 0
    		m = 2 * currx;
    		b = (-m*currx)  + curry;
    		root = -b / m;
    		currx = root;
    	}
    //	trace << "tries: " << tries << "\n";
    	return root;
    }
    EDIT: Mine is a lot slower than normal sqrt, but I'm glad that it at least works.
    Last edited by Silvercord; 12-10-2003 at 04:34 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  2. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. OpenGL camera errors..can't find 'em!?
    By psychopath in forum Game Programming
    Replies: 12
    Last Post: 04-22-2004, 06:17 PM
  5. Camera rotation/movement in 3D world
    By tegwin in forum Game Programming
    Replies: 11
    Last Post: 01-24-2003, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21