Advertisement
| 11.30.2008 at 11:40AM PST, ID: 23945218 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: |
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include "bmp_io.h"
using namespace std;
//From the trackball program
#define bool int
#define false 0
#define true 1
#define M_PI 3.14159
//Globals from the trackball
float nnear = 3.0; /* near clipping plane in eye coords */
float nfar = 7.0; /* far clipping plane in eye coords */
float viewxform_z = -5.0;
int winWidth, winHeight;
float angle = 0.0, axis[3];
// bool trackballMove = false;
bool redrawContinue = false;
GLfloat objectXform[4][4] = {
{1.0, 0.0, 0.0, 0.0},
{0.0, 1.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 0.0},
{0.0, 0.0, 0.0, 1.0}
};
void display(void);
void spinCube(void);
const int numImages = 6;
static GLuint texName[numImages];
char fileNames[numImages][140] = {"C:\\Documents and Settings\\anthony\\My Documents\\engineering\\visualization\\P_3_McNally_Anthony\\Program 3\\Blue hills.bmp", "C:\\Documents and Settings\\anthony\\My Documents\\engineering\\visualization\\P_3_McNally_Anthony\\Program 3\\r_moms_diner.bmp",
"C:\\Documents and Settings\\anthony\\My Documents\\engineering\\visualization\\P_3_McNally_Anthony\\Program 3\\Sunset.bmp", "C:\\Documents and Settings\\anthony\\My Documents\\engineering\\visualization\\P_3_McNally_Anthony\\Program 3\\Sports_SeahawksVsCowboys2.bmp",
"C:\\Documents and Settings\\anthony\\My Documents\\engineering\\visualization\\P_3_McNally_Anthony\\Program 3\\Winter.bmp", "C:\\Documents and Settings\\anthony\\My Documents\\engineering\\visualization\\P_3_McNally_Anthony\\Program 3\\DSCN0301.bmp"};
unsigned long int widths[numImages];
long int heights[numImages];
unsigned char *images[numImages];
int s0 = 0;
//vertices of the cube
float vertices[8][3] = {{0.5, -0.5, -0.5}, {0.5, 0.5, -0.5}, {-0.5, 0.5, -0.5},
{-0.5, -0.5, -0.5}, {0.5, -0.5, 0.5}, {0.5, 0.5, 0.5}, {-0.5, 0.5, 0.5}, {-0.5, -0.5, 0.5}};
//normals of the faces
float normal[6][3] = {{0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0},
{-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}};
//reads the 6 different image files
void readFiles()
{
bmp_byte_swap_set ( true );
for (int i = 0; i < numImages; i++)
{
unsigned char *rarray = NULL, *garray = NULL, *barray = NULL;
unsigned long int width;
long int height;
if (bmp_read(fileNames[i], &width, &height, &rarray, &garray, &barray))
cout << "Failed to read file " << fileNames[i] << ".\n";
rarray = new unsigned char[width * height];
garray = new unsigned char[width * height];
barray = new unsigned char[width * height];
images[i] = new unsigned char[width * height * 4];
widths[i] = width;
heights[i] = height;
bmp_read(fileNames[i], &width, &height, &rarray, &garray, &barray);
for (int j = 0; j < long(width * height); j++)
{
images[i][j * 4] = rarray[j];
images[i][j * 4 + 1] = garray[j];
images[i][j * 4 + 2] = barray[j];
images[i][j * 4 + 3] = 255;
}
delete [] rarray;
delete [] garray;
delete [] barray;
}
}
//initializes the program
void init (void)
{
glClearColor (0.0, 0.0, 0., 0.0);
glPolygonMode(GL_FRONT, GL_FILL);
//sets up the light position ambient diffuse and specular values
GLfloat light_pos[] = {0.0, 0.0, 0.0, 1.0};
GLfloat light_ambient[] = {0.1, 0.1, 0.1, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
//creates the light
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
readFiles();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(numImages, texName);
for (int i = 0; i < numImages; i++)
{
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widths[i], heights[i],
0, GL_RGBA, GL_UNSIGNED_BYTE, images[i]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
glEnable(GL_TEXTURE_2D);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glMatrixMode(GL_PROJECTION);
glOrtho(-2.0, 2.0, -2.0, 2.0, nnear, nfar);
viewxform_z = -5.0;
}
// creates the object texture cube
void textureCube()
{
//Starts drawing the cube and the associated textures
glBindTexture(GL_TEXTURE_2D, texName[0]);
glBegin(GL_QUADS);
//Top face
glNormal3fv(normal[0]);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[0]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[1]);
glTexCoord2f(1.0, 1.0); glVertex3fv(vertices[5]);
glTexCoord2f(0.0, 1.0); glVertex3fv(vertices[4]);
glEnd();
//Bottom face
glBindTexture(GL_TEXTURE_2D, texName[1]);
glBegin(GL_QUADS);
glNormal3fv(normal[1]);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[2]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[3]);
glTexCoord2f(1.0, 1.0); glVertex3fv(vertices[7]);
glTexCoord2f(0.0, 1.0); glVertex3fv(vertices[6]);
glEnd();
//Right face
glBindTexture(GL_TEXTURE_2D, texName[2]);
glBegin(GL_QUADS);
glNormal3fv(normal[2]);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[5]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[1]);
glTexCoord2f(1.0, 1.0); glVertex3fv(vertices[2]);
glTexCoord2f(0.0, 1.0); glVertex3fv(vertices[6]);
glEnd();
//Left face
glBindTexture(GL_TEXTURE_2D, texName[3]);
glBegin(GL_QUADS);
glNormal3fv(normal[3]);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[0]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[4]);
glTexCoord2f(1.0, 1.0); glVertex3fv(vertices[7]);
glTexCoord2f(0.0, 1.0); glVertex3fv(vertices[3]);
glEnd();
//Front face
glBindTexture(GL_TEXTURE_2D, texName[4]);
glBegin(GL_QUADS);
glNormal3fv(normal[4]);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[7]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[4]);
glTexCoord2f(1.0, 1.0); glVertex3fv(vertices[5]);
glTexCoord2f(0.0, 1.0); glVertex3fv(vertices[6]);
glEnd();
//Rear face
glBindTexture(GL_TEXTURE_2D, texName[5]);
glBegin(GL_QUADS);
glNormal3fv(normal[5]);
glTexCoord2f(1.0, 0.0); glVertex3fv(vertices[1]);
glTexCoord2f(1.0, 1.0); glVertex3fv(vertices[0]);
glTexCoord2f(0.0, 1.0); glVertex3fv(vertices[3]);
glTexCoord2f(0.0, 0.0); glVertex3fv(vertices[2]);
glEnd();
}
//creates what is displayed on the screen
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
{
glPushMatrix();
glRotatef(angle, axis[0], axis[1], axis[2]);
glMultMatrixf((GLfloat *) objectXform);
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) objectXform);
glPopMatrix();
glLoadIdentity();
}
glMultMatrixf((GLfloat *) objectXform);
textureCube();
glEnable(GL_LIGHTING);
//glColor3f(0, 1, 0);
////Draws the box for the entire cube
//glBegin(GL_QUADS);
////draws the top square
//glNormal3f(1.0, 0.0, 0.0);
//glVertex3fv(vertices[0]);
//glVertex3fv(vertices[1]);
//glVertex3fv(vertices[5]);
//glVertex3fv(vertices[4]);
////draws the bottom square
//glNormal3f(-1.0, 0.0, 0.0);
//glVertex3fv(vertices[3]);
//glVertex3fv(vertices[2]);
//glVertex3fv(vertices[6]);
//glVertex3fv(vertices[7]);
////draws the right square
//glNormal3f(0.0, 1.0, 0.0);
//glVertex3fv(vertices[5]);
//glVertex3fv(vertices[1]);
//glVertex3fv(vertices[2]);
//glVertex3fv(vertices[6]);
////draws the left square
//glNormal3f(0.0, -1.0, 0.0);
//glVertex3fv(vertices[0]);
//glVertex3fv(vertices[4]);
//glVertex3fv(vertices[7]);
//glVertex3fv(vertices[3]);
//glBegin(GL_QUADS);
////draws the front square
//glNormal3f(0.0, .0, 1.0);
//glVertex3fv(vertices[4]);
//glVertex3fv(vertices[5]);
//glVertex3fv(vertices[6]);
//glVertex3fv(vertices[7]);
//glEnd();
////draws the rear square
//glNormal3f(0.0, 0.0, -1.0);
//glVertex3fv(vertices[1]);
//glVertex3fv(vertices[0]);
//glVertex3fv(vertices[3]);
//glVertex3fv(vertices[2]);
//glEnd();
//Section for adding textures
////Adds texture to the top square
//glBindTexture(GL_TEXTURE_2D, texName[s0]);
//glBegin(GL_QUADS);
// glNormal3f(1, 0, 0);
// glTexCoord2f(0.0, 0.0);
// glVertex3fv(vertices[0]);
// glTexCoord2f(1.0, 0.0);
// glVertex3fv(vertices[1]);
// glTexCoord2f(1.0, 1.0);
// glVertex3fv(vertices[5]);
// glTexCoord2f(0.0, 1.0);
// glVertex3fv(vertices[4]);
//glEnd();
//
//////adds texture to the bottom square
//glBindTexture(GL_TEXTURE_2D, texName[1]);
//glBegin(GL_QUADS);
// glNormal3f(-1, 0, 0);
// glTexCoord2f(0.0, 0.0);
// glVertex3fv(vertices[2]);
// glTexCoord2f(1.0, 0.0);
// glVertex3fv(vertices[3]);
// glTexCoord2f(1.0, 1.0);
// glVertex3fv(vertices[7]);
// glTexCoord2f(0.0, 1.0);
// glVertex3fv(vertices[6]);
//glEnd();
//////adds texture to the right Square
//glBindTexture(GL_TEXTURE_2D, texName[2]);
//glBegin(GL_QUADS);
// glNormal3f(0, 1, 0);
// glTexCoord2f(0.0, 0.0);
// glVertex3fv(vertices[5]);
// glTexCoord2f(1.0, 0.0);
// glVertex3fv(vertices[1]);
// glTexCoord2f(1.0, 1.0);
// glVertex3fv(vertices[2]);
// glTexCoord2f(0.0, 1.0);
// glVertex3fv(vertices[6]);
//glEnd();
//////adds texture to the left square
//glBindTexture(GL_TEXTURE_2D, texName[3]);
//glBegin(GL_QUADS);
// glNormal3f(0, -1, 0);
// glTexCoord2f(0.0, 0.0);
// glVertex3fv(vertices[0]);
// glTexCoord2f(1.0, 0.0);
// glVertex3fv(vertices[4]);
// glTexCoord2f(1.0, 1.0);
// glVertex3fv(vertices[7]);
// glTexCoord2f(0.0, 1.0);
// glVertex3fv(vertices[3]);
//glEnd();
//////adds texture to the front
//glBindTexture(GL_TEXTURE_2D, texName[4]);
//glBegin(GL_QUADS);
// glNormal3f(0, 0, 1);
// glTexCoord2f(0.0f, 0.0f);
// glVertex3fv(vertices[4]);
// glTexCoord2f(1.0f, 0.0f);
// glVertex3fv(vertices[5]);
// glTexCoord2f(1.0f, 1.0f);
// glVertex3fv(vertices[6]);
// glTexCoord2f(0.0f, 1.0f);
// glVertex3fv(vertices[7]);
//glEnd();
////////adds texture to the rear
//glBindTexture(GL_TEXTURE_2D, texName[5]);
//glBegin(GL_QUADS);
// glNormal3f(0, 0, -1);
// glTexCoord2f(1.0, 0.0);
// glVertex3fv(vertices[1]);
// glTexCoord2f(1.0, 1.0);
// glVertex3fv(vertices[0]);
// glTexCoord2f(0.0, 1.0);
// glVertex3fv(vertices[3]);
// glTexCoord2f(0.0, 0.0);
// glVertex3fv(vertices[2]);
//glEnd();
glutSwapBuffers();
glFlush ();
}
//-------------implements a trackball motion--------------//
float lastPos[3] = {0.0F, 0.0F, 0.0F};
int startX, startY;
void trackball_ptov(int x, int y, int width, int height, float v[3])
{
float d, a;
/* project x, y onto a hemi-sphere centered within width, height */
v[0] = (2.0F * x - width) / width;
v[1] = (height - 2.0F * y) / height;
d = (float) (v[0] * v[0] + v[1] * v[1]);
//v[2] = (float) cos((M_PI/2.0F) * ((d < 1.0F) ? d : 1.0F));
v[2] = (float) sqrt(1 - ((d < 1.0F) ? d : 1.0F));
a = 1.0F / (float) sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
v[0] *= a;
v[1] *= a;
v[2] *= a;
}
void mouseMotion(int x, int y)
{
float curPos[3], dx, dy, dz;
trackball_ptov(x, y, winWidth, winHeight, curPos);
dx = curPos[0] - lastPos[0];
dy = curPos[1] - lastPos[1];
dz = curPos[2] - lastPos[2];
if (dx || dy || dz) {
angle = 90.0F * sqrt(dx * dx + dy * dy + dz * dz) / 3;
axis[0] = lastPos[1] * curPos[2] - lastPos[2] * curPos[1];
axis[1] = lastPos[2] * curPos[0] - lastPos[0] * curPos[2];
axis[2] = lastPos[0] * curPos[1] - lastPos[1] * curPos[0];
lastPos[0] = curPos[0];
lastPos[1] = curPos[1];
lastPos[2] = curPos[2];
}
glutPostRedisplay();
}
void startMotion(int x, int y)
{
redrawContinue = false; // Initial mouse click stops the motion.
startX = x; startY = y;
trackball_ptov(x, y, winWidth, winHeight, lastPos);
}
void stopMotion(int x, int y)
{
if (startX != x || startY != y)
redrawContinue = true;
else
redrawContinue = false;
}
void spinCube()
{
if (redrawContinue) glutPostRedisplay();
}
void mouseButton(int button, int state, int x, int y)
{
switch(state)
{
case GLUT_DOWN:
startMotion(x, y);
break;
case GLUT_UP:
stopMotion(x, y);
break;
}
}
//---------End of trackball motions-----------------//
//reshapes the window when it is changed
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30, (float) w / h, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
}
//creates the keyboard functions
void keyboard(unsigned char key, int x, int y)
{
if (key == 'q' || key == 'Q' || key == 27)
exit(0);
}
//creates the menu functions
void topMenuFunc(int id)
{
switch (id)
{
case 1:
break;
case 2:
break;
case 5:
break;
case 6:
break;
}
glutPostRedisplay();
}
//creates the menu when the right mouse button is clicked
void createMenu()
{
int topMenu;
topMenu = glutCreateMenu(topMenuFunc);
glutAddMenuEntry("Reset", 6);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
//The main section of the program
int main(int argc, char** argv)
{
//int topMenu;
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Picture Cube");
createMenu();
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutIdleFunc(spinCube);
glutMouseFunc(mouseButton);
glutMotionFunc(mouseMotion);
glutMainLoop();
return 0;
}
|
Advertisement