#include "stdafx.h"
#include "glut.h"
#include "DianaCode-Proj2.h"
/* This program is a basic test of openGL using the GLUT tool kit. Details of this program
are found in chapter 2 of the book startng around page 45. */
void main(int argc, char **argv)
{
/* Routines called. */
void myInit(void);
void Mean(void);
/* Put text message out to show that program is working. */
printf("hello tv land! \n");
glutInit(&argc, argv); /* Initialize glut tool kit. */
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); /* Set display mode to single buffer, color. */
glutInitWindowSize(640, 480); /* Set window size to 640 by 480 pixels. */
glutInitWindowPosition(0,0); /* Set window 0 from left edge of screen, 0 down from top. */
glutCreateWindow("Project 3"); /* Create window with title. */
glutDisplayFunc(Mean); /* Register Draw function. */
myInit(); /* Initialize window. */
glutMainLoop(); /* Go into monitor loop. */
printf("press any key to quit");//window label
getchar();
}
void myInit(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-13,13,-13,13);//set points on graph
}
void Mean(){
FILE *in;//calls up the file curveData.txt
float x, y;//variables to be used: x for first column and y for second column
float xs[200], ys[200];//sets each varible to it's own array
int count;//for use later when we calculate the amount of points in the array
float sum = 0;//for use when we calculate the total of all values
float totalY, totalX;//this will be the variable for the total amount in x and y
glClear(GL_COLOR_BUFFER_BIT); /* Clear the drawing buffer. */
in = fopen("curveData.txt", "r");//opens the file for reading data in curveData.txt, r is for reading the file
if (in == NULL) {
printf("Error: Cannot open input file. \n");//prints if the file didn't open
exit(0);//exits if file not opened
}
//initiate variables to zero before used
count = 0;//set count to zero before using
totalY = 0;//set totalY to zero
totalX = 0;//set totalX to zero
int i;//initialize variable
float averageY = 0;//sets averageY to zero and sets to type float
float averageX = 0;//sets averageX to zero and sets to type float
while (fscanf_s(in, "%f %f", &x, &y) != EOF) {//open file to read numbers
xs[count] = x;//counts the x values
ys[count] = y;//counts the y values
count++;//counts then iterates plus one
totalY = totalY + y;//adds numbers in column Y then goes to the next in Y column
totalX = totalX + x;//adds numbers in column X then goes to the next in X column
averageX += x; //add all numbers and divide by # of points to get average x values
averageY += y; // add all numbers and divide by # of points to get average y values
}
printf("We found %d points in the file. \n", count);//states how many numbers are in column Y
printf("This is the total y values: %f\n", totalY);//prints added numbers in the Y column
averageY = float(totalY)/(count);//calculates total(# of y)/average(#of points) of Y column
averageX = float(totalX)/(count);//calculates total/average of Y column
float distanceX = 0.0f;
float stddevX = 0.0f;
float distanceY = 0.0f;//sets up for the distanceY formula to come
float stddevY = 0.0f;//sets up the standard deviation formula to come
for(i=0; i<count; i++)//loop for iterating through each point of Y
{
distanceX = xs[i] - averageX;
stddevX += (distanceX *= distanceX);
distanceY = ys[i] - averageY;//array for y points minus the average
stddevY += (distanceY *= distanceY);//sets the stddev to distanceY squared for calculating standard deviation
}
stddevX /= count;//divides each number in the standard deviation by the number of count
stddevY /= count;//divides each number in the standard deviation by the number of count
stddevY = sqrt(stddevY);//calculates the square root of the standard deviation
float maxy = averageY + (stddevY * 1.2);//shows the max value of the standard deviation of Y values
float miny = averageY - (stddevY * 1.2);//shows the min value of the standard deviation of Y values
printf("This is the average y values: %f\n", averageY);//prints average of Y values
printf("This is the standard deviation values: %f\n", stddevY);//prints std dev of Y values
printf("this is the max of Y %f\n", maxy);//this is the max of Y values
printf("this is the min of Y %f\n", miny);//this is the min of Y values
//begin generating line
glBegin(GL_LINE_STRIP);//draw points on screen
for( i = 0; i < count; i++){
if ((maxy < ys[i]) || (miny > ys[i])){
printf("Want to remove points %f,%f\n", xs[i], ys[i]);
}
else{
glVertex2f(xs[i], ys[i]);
}
}
glEnd();
//float newY = ((ys[i]/maxy-miny)*((-250-640)+250));
glFlush();
}
Trying to scale a graph in a toolbox I'm building in C++ and GLUTNeed help scaling C++ and GLUT
Page 1 of 1
1 Replies - 639 Views - Last Post: 19 March 2009 - 08:58 AM
#1
Trying to scale a graph in a toolbox I'm building in C++ and GLUT
Posted 18 March 2009 - 05:14 PM
Using VS2008, programming in C++ with GLUT...trying to build my toolkit and practicing. I want to scale this graph, "curveData.txt" but I just am having the fits getting my head wrapped around this....Can anyone help??
Replies To: Trying to scale a graph in a toolbox I'm building in C++ and GLUT
#2
Re: Trying to scale a graph in a toolbox I'm building in C++ and GLUT
Posted 19 March 2009 - 08:58 AM
SITE questions & forums applies to this site, not any site. wrong forum.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|