Thread: Array and classes problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    9

    Array and classes problem

    Sorry tabstop, I completed the question and made it better.
    -----------------------------------------------------------

    I have a class like such:

    Code:
    class Sphere 
    {
    public:
    	Sphere(){};
    	~Sphere() {};
    	Sphere(string m_name) : name(m_name) {};
    	void SetValues(float m_posx, float m_posy, float m_posz,
    					float m_sclx, float m_scly, float m_sclz,
    					float m_r, float m_g, float m_b,
    					float m_Ka, float m_Kd, float m_Ks, float m_Kr,
    					float m_n)
    	{
    		Ka = m_Ka; Kd = m_Kd; Ks = m_Ks; Kr = m_Kr;
    		n = m_n;
    		radius = 1.00;
    		center.x  =  0.00; center.y = 0.00; center.z = 0.00;
    		sphereColor.r = m_r; 
    		sphereColor.g = m_g;
    		sphereColor.b = m_b;
    		SetTranformMatrix(m_posx, m_posy, m_posz,
    						  m_sclx, m_scly, m_sclz);
    	};
    
    		
    	
    	         //set the transfor matrix
    	void SetTranformMatrix( float posx, float  posy, float posz,
    							float sclx, float  scly, float sclz)	
    	{
    		Trans[0][0] = sclx;
    		Trans[0][1] = 0;
    		Trans[0][2] = 0;
    		Trans[0][3] = posx;
    		Trans[1][0] = 0;
    		Trans[1][1] = scly;
    		Trans[1][2] = 0;
    		Trans[1][3] = posy;
    		Trans[2][0] = 0;
    		Trans[2][1] = 0;
    		Trans[2][2] = sclz;
    		Trans[2][3] = posz;
    		Trans[3][0] = 0;
    		Trans[3][1] = 0;
    		Trans[3][2] = 0;
    		Trans[3][3] = 1;
    	};
    
                   //should return the depth at which the the ray has intersected otherwise return -1;
    	double intersect(ray &m_ray)
    	{
    
    		double T_Inverse[4][4];
    		invert_matrix(Trans, T_Inverse);
    
                   //buncha lines here
    	}
      
    	std::string name;
    	double Trans[4][4];	//transition matrix
    	color sphereColor;
    
    private:
    	point center;
    	double radius;
    	float Ka, Kd, Ks, Kr;
    	float n;	//specular 
    
    };
    and a function like such:
    Code:
    float compute_closest_intersection(ray &m_ray, Sphere * m_spheres)
    {
    	float intersect = -1;
    	float temp_intersect;
    	for(int i=0; i < 3; i++)
    	{
    		temp_intersect = m_spheres[i].intersect(m_ray); //HERE HERE HERE HERE 
    		intersect = (temp_intersect >= intersect) ?  temp_intersect : intersect;
    	}
    	return intersect;
    }
    and in main I have
    Code:
    Sphere inputSphere[5];
    float testiii = compute_closest_intersection(Thru_Pixel,InputSphere);
    - and the problem: Trans[][] doesn't have values,
    (where it was initialized in the SetTranformMatrix() function)
    when the intersect is called from compute_closest_intersection function.

    in a nutshell

    Why doesn't Trans[][] keep the values assigned to it in the SetTranformMatrix() function.


    -Thank you
    Last edited by armen; 11-17-2008 at 04:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of classes?
    By dream_noir in forum C++ Programming
    Replies: 2
    Last Post: 03-22-2009, 11:43 AM
  2. Overloading Array Objects for use with Classes
    By ibleedart in forum C++ Programming
    Replies: 2
    Last Post: 10-24-2007, 06:48 PM
  3. copy array of classes or explicity call constructor
    By Doodle77 in forum C++ Programming
    Replies: 5
    Last Post: 06-10-2007, 11:57 AM
  4. two-dimensional dynamic array of pointers to classes
    By Timo002 in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 06:18 AM
  5. 2d Array access by other classes
    By deaths_seraphim in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2001, 08:05 AM