Archived

This topic is now archived and is closed to further replies.

taybrin

Class header woes

Recommended Posts

taybrin    122
okay everyone i have the following header file:
  
#ifndef TORUS_O
#define TORUS_O

#include <GL/glut.h>
#include <iostream.h>
#include "Shape.h"
#include <math.h>

#define DEGREE_TO_RADIAN (3.1415926535 / 180)

class Torus : public virtual Shape
{

private:
	GLfloat radius1;
	GLfloat radius2;
	int slices1;
	int slices2;
	
	char * name;
	char * material_name;

	GLfloat (*vList)[3];
	GLfloat (*nList)[3];
	int num_vertices;

	
public:
	
	virtual void draw();
	virtual void computeVerticesNormals();
	virtual char * getMaterialName();

	Torus(char *, char *, GLfloat, GLfloat, int, int);

	~Torus() 
	{
		delete [] vList;
		delete [] nList;
	};

};

#endif
  
And i have the .cpp file
  
#include "Torus.h"
#include <stdio.h>


Torus::Torus(char * n, char * mat_name, GLfloat rad1, GLfloat rad2, int slices1, int slices2) : 
			slices1(slices1),
			slices2(slices2),
			radius1(rad1),
			radius2(rad2)
{
	name = new char(strlen(n)+1);
	strcpy(name, n);

	material_name = new char(strlen(mat_name)+1);
	strcpy(material_name, mat_name);

	/* figure out what the number of points is */
	num_vertices = slices1 * slices2;
	vList = new GLfloat[num_vertices][3];
	nList = new GLfloat[num_vertices][3];

	computeVerticesNormals();

}

void
Torus::computeVerticesNormals() 
{

	GLfloat degree_inc_outer = 360 / (GLfloat)slices1;
	GLfloat degree_inc_inner = 360 / (GLfloat)slices2;

	int cur_ver = 0;
	for(int i = 0; i < slices1; i++) {
		for(int j = 0; j < slices2; j++) { 
			vList[cur_ver][0] = radius2 * sin(j * degree_inc_inner * DEGREE_TO_RADIAN);
			vList[cur_ver][1] = sin(i * degree_inc_outer * DEGREE_TO_RADIAN) * (radius1 +  radius2 * cos(j * degree_inc_inner * DEGREE_TO_RADIAN));
			vList[cur_ver][2] = cos(i * degree_inc_outer * DEGREE_TO_RADIAN) * (radius1 + radius2 * cos(j * degree_inc_inner * DEGREE_TO_RADIAN));

			nList[cur_ver][0] = vList[cur_ver][0];
			nList[cur_ver][1] = vList[cur_ver][1] - sin(i * degree_inc_outer * DEGREE_TO_RADIAN) * radius1;
			nList[cur_ver][2] = vList[cur_ver][2] - cos(i * degree_inc_outer * DEGREE_TO_RADIAN) * radius1;
		cur_ver++;
		}		
	}
}

void
Torus::draw()
{
	
	int cur_ver = 0;
	int top_ind;
	for(int i = 1; i <= slices2; i++) {
		glBegin(GL_QUAD_STRIP);
			if((cur_ver+1) % slices2 == 0 && cur_ver != 0) {
				top_ind = 0;
			}
			else top_ind = cur_ver + 1;
			for(int j = 1; j <= slices1; j++) {
				glNormal3fv(nList[top_ind + (slices2*(j-1))%(num_vertices)]);
		//	printf("top_ind %d used vertex %d\n", top_ind, ((top_ind) + (slices2*(j-1)))%(num_vertices));
				glVertex3fv(vList[((top_ind) + (slices2*(j-1)))%(num_vertices)]);

		//		printf("bottom_ind %d used vertex %d\n", cur_ver, (cur_ver + (slices2*(j-1)))%(num_vertices));
				glNormal3fv(nList[cur_ver + (slices2*(j-1))%(num_vertices)]);
				glVertex3fv(vList[(cur_ver + (slices2*(j-1)))%(num_vertices)]);
			}
	//		printf("top_ind %d used vertex %d\n", top_ind, top_ind);
			glNormal3fv(nList[top_ind]);
			glVertex3fv(vList[top_ind]);

	//		printf("bottom_ind %d used vertex %d\n", cur_ver, cur_ver);
			glNormal3fv(nList[cur_ver]);
			glVertex3fv(vList[cur_ver]);

			cur_ver++;
		glEnd();
	}
	
/*	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glColor3f(0.0, 1.0, 0.0);
	glBegin(GL_POINTS);
	for(int k = 0; k < num_vertices; k++) {
		glVertex3fv(vList[k]);
	}
	glEnd(); 
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);*/
}

char *
Torus::getMaterialName() { return material_name; }
  
When I compile i get these horrible weird errors, someone please help . . . Torus.cpp c:\myprojects\scene graph\torus.cpp(5) : error C2143: syntax error : missing '')'' before ''constant'' c:\myprojects\scene graph\torus.cpp(5) : error C2143: syntax error : missing '';'' before ''constant'' c:\myprojects\scene graph\torus.cpp(5) : error C2244: ''Torus::Torus::Torus'' : unable to resolve function overload c:\myprojects\scene graph\torus.cpp(5) : fatal error C1004: unexpected end of file found

Share this post


Link to post
Share on other sites
Viscous-Flow    122
I think I have found your problem.

You have this statement:
    
~Torus()
{
delete [] vList;
delete [] nList;
};


Now you see that semicolon after the last brace?

That shouldn't be there. You only put semicolons after the last brace in a class decleration, also in structs as well.

Functions don't have semicolons after their braces, which ~Torus() is.

Good Luck !

Edited by - Viscous-Flow on November 4, 2001 3:01:49 AM

Share this post


Link to post
Share on other sites
Null and Void    1088
You can put semicolons almost anywhere you want to. They just aren''t required after functions. I think the error may be in the
  
slices1(slices1),
slices2(slices2),

part. Are you sure you''re allowed to have the parameters named the same thing as the member variables and still assign them like that? Try naming the parameters something different.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
taybrin    122
thats not the problem , i have tried that, and i have about 4 other different classes that extend Shape and the only one to complain about the format of my header is Torus. Any more suggestions

Share this post


Link to post
Share on other sites
Lestat3D    122
Try naming your class "CTorus" instead "Torus".
If you have two files named adfx.h and adfx.cpp or something like that, you must make an empty project to start programming in vc++.

Share this post


Link to post
Share on other sites
taybrin    122
okay i tried everything, no luck, like i was saying i have a Sphere class and it works great. To make the Torus class i copied the Sphere.cpp and Sphere.h files and changed just everything to Torus, adjusted the constructor and changed the internals of the functions. Its the weirdest freakin'' error - -

Share this post


Link to post
Share on other sites
Viscous-Flow    122
quote:
Original post by Null and Void
You can put semicolons almost anywhere you want to. They just aren''t required after functions.


Wow, thanks, I never knew that, hehe. I tried it out and printed about 20 ; after a function and the compiler never generated an error.

Your 2 cool Null and Void.

Share this post


Link to post
Share on other sites
taybrin    122
NULL, i have tried that too, to be honest i got these errors before using your method, so i ripped the constructor out of the .h file and then somewhere in the mix these errors came back

Share this post


Link to post
Share on other sites