PDA

View Full Version : سوال: مشکل در رسم نمودار دایره ای در open gl



majidariamanesh
پنج شنبه 05 اردیبهشت 1392, 22:48 عصر
من می خوام نمودار دایره ای با open gl رسم کنم اما کدم جواب نمیده
کسی میدونه مشکلش چیه؟

بعد باید برچسب هم به نمودار بزنم کسی میتونه راهنمایی کنه؟


#include <glut.h>
#include <stdlib.h>
#include <math.h>

const GLdouble towPi = 6.283185 ;

class scrPt
{
public :
GLint x,y;
};

class screenPt
{
private :
GLint x , y;
public:
screenPt()
{
x = y = 0;
}

void setCoords(GLint xCoordValue ,GLint yCoordValue )
{
x = xCoordValue;
y = yCoordValue;
}

GLint getx() const
{
return x;
}

GLint gety() const
{
return y;
}

void incX ()
{
x++;
}

void decY ()
{
y--;
}
};

GLsizei winWidth = 400 , winHeight = 300 ;

void init(void)
{
glClearColor (1.0 , 1.0 , 1.0 , 1.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D(0.0 , 200.0 , 0.0 , 150.0);
}

void setPixel (GLint xCoord , GLint yCoord)
{
glBegin(GL_POINTS);
glVertex2i(xCoord , yCoord);
glEnd();
}

void circleMidPoint(GLint xc , GLint yc , GLint radius)
{
screenPt circPt ;

GLint p = 1 - radius ;

circPt.setCoords(0,radius);

void circleplotPoint(GLint ,GLint , screenPt);

circleplotPoint(xc , yc , circPt);

while (circPt.getx()<circPt.gety())
{
circPt.incX();
if (p < 0)
p += 2 * circPt.getx()+1;
else
{
circPt.decY();
p += 2 * (circPt.getx() - circPt.gety()) + 1;

}

circlePlotPoints(xc , yc , circPt);
}
}

void circlePlotPoints(GLint xc , GLint yc , screenPt circPt)
{
setPixel(xc + circPt.getx(),yc + circPt.gety());
setPixel(xc - circPt.getx(),yc + circPt.gety());
setPixel(xc + circPt.getx(),yc - circPt.gety());
setPixel(xc - circPt.getx(),yc - circPt.gety());
setPixel(xc + circPt.getx(),yc + circPt.gety());
setPixel(xc - circPt.getx(),yc + circPt.gety());
setPixel(xc + circPt.getx(),yc - circPt.gety());
setPixel(xc - circPt.getx(),yc - circPt.gety());
}

void pieChart(void)
{
scrPt circCtr , piePt;
GLint radius = winWidth / 4;

GLdouble sliceAngle , perviosSliceAngle = 0.0;

GLint k , nSlices = 12 ;
GLfloat dataValues [12] = {10.0 , 7.0 , 13.0 , 5.0 , 13.0 , 14.0 , 3.0 , 16.0 , 5.0 , 3.0, 17.0 , 8.0 };

GLfloat dataSum = 0.0;

circCtr.x = winWidth/2;
circCtr.y = winHeight/2;

circleMidPoint(circCtr.x,circCtr.y , radius);

for (k = 0 ; k < nSlices ; k++ )
dataSum += dataValues [k];

for (k = 0 ; k < nSlices ; k++)
{
sliceAngle = towPi * dataValues[k] / dataSum + perviosSliceAngle ;
piePt.x = circCtr.x + radius * cos(sliceAngle);
piePt.y = circCtr.y + radius * sin(sliceAngle);

glBegin (GL_LINES);
glVertex2i (circCtr.x , circCtr.y);
glVertex2i (piePt.x , piePt.y);
glEnd();

perviosSliceAngle = sliceAngle;
}
}

void displayFcn(void)
{
glClearColor(GL_COLOR_BUFFER_BIT);

glColor3f (0.0 , 0.0 ,1.0);

pieChart();
glFlush();
}

void winReshapeFcn(GLint newWidth , GLint newHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0 , GLdouble (newWidth) , 0.0 , GLdouble (newHeight) );

glClear(GL_COLOR_BUFFER_BIT);

winWidth = newWidth ;
winHeight = newHeight;


}


void main (int argc , char **argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowPosition(100,100);
glutInitWindowSize(winWidth , winHeight);

glutCreateWindow("nemodar by majid ahmadi");

init ();

glutDisplayFunc (displayFcn);

glutReshapeFunc(winReshapeFcn);

glutMainLoop();
}

UfnCod3r
جمعه 06 اردیبهشت 1392, 08:28 صبح
خب بگو مشکلت دقیقا چیه
فکرکنم اینو بنویسی درست بشه


gluOrtho2D(0,200,200,0)

اینطوری بالا چپ میشه 0و0 و پایین راست میشه 200و200
:لبخندساده:

majidariamanesh
جمعه 06 اردیبهشت 1392, 09:59 صبح
ببینید وقتی می خواد اجرا بشه این ارور رو میده
Error 1 error C2381: 'exit' : redefinition; __declspec(noreturn) differs c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h 353 1 opengl1

majidariamanesh
جمعه 06 اردیبهشت 1392, 10:04 صبح
Error 1 error C2381: 'exit' : redefinition; __declspec(noreturn) differs c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h 353 1 opengl1