int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL); windowWidth = 512; windowHeight = 512; zNear = 0.1f; zFar = 1000.0f; fov = 45.0f; glutInitWindowSize (windowWidth, windowHeight); glutInitWindowPosition (100, 100); glutCreateWindow("Exercise 10"); glutReshapeFunc(resizeGL); glutDisplayFunc(updateGL); glutIdleFunc(idle); glutKeyboardFunc(keyboardEvent); glutMouseFunc(mouseEvent); glutMotionFunc(mouseMoveEvent); GLenum err = glewInit(); if (GLEW_OK != err) { fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); initGL(); initFBO(); initScene(); // this path defines a looped circular curve // std::vector<ControlPoint> p; p.push_back(ControlPoint( 1.0, 0.0, 0.0, 0.0)); p.push_back(ControlPoint( 0.7, 0.0, 0.7, 0.5)); p.push_back(ControlPoint( 0.0, 0.0, 1.0, 1.0)); p.push_back(ControlPoint(-0.7, 0.0, 0.7, 1.5)); p.push_back(ControlPoint(-1.0, 0.0, 0.0, 2.0)); p.push_back(ControlPoint(-0.7, 0.0,-0.7, 2.5)); p.push_back(ControlPoint( 0.0, 0.0,-1.0, 3.0)); p.push_back(ControlPoint( 0.7, 0.0,-0.7, 3.5)); p.push_back(ControlPoint( 1.0, 0.0, 0.0, 4.0)); mPath.setFirstControlPoint(p[p.size() - 2]); mPath.setLastControlPoint(p[1]); for (unsigned int i = 0; i < p.size(); ++i) { mPath.addIntermediateControlPoint(p[i]); } mPath.setLooped(true); // ----------------------------------------- // glutMainLoop(); delete mNormalMapShader; return 0; }
// provide a default set of points void World::resetPoints() { points.clear(); points.push_back(ControlPoint(Pnt3f(50,5,0))); points.push_back(ControlPoint(Pnt3f(0,5,50))); points.push_back(ControlPoint(Pnt3f(-50,5,0))); points.push_back(ControlPoint(Pnt3f(0,5,-50))); // we had better put the train back at the start of the track... trainU = 0.0; }
//**************************************************************************** // // * provide a default set of points //============================================================================ void CTrack:: resetPoints() //============================================================================ { mDeleteAll(); CPs.clear(); mAdd(ControlPoint(Ogre::Vector3( 50, 10, 0))); mAdd(ControlPoint(Ogre::Vector3( 0, 10, 50))); mAdd(ControlPoint(Ogre::Vector3( -50, 10, 0))); mAdd(ControlPoint(Ogre::Vector3( 0, 10, -50))); }
Vehicle::Vehicle(){ ifstream myfile; myfile.open ("vehicle.btp"); int number; myfile>>number; for(int i=0;i<number;i++) { vector<ControlPoint> aux; aux.clear(); int order1,order2; float x,y,z; myfile>>order1>>order2; for(int j=0;j<16;j++) { myfile>>x>>y>>z; aux.push_back(ControlPoint(x,y,z)); } Patch* p1=new Patch(order1, 5,5, "fill", aux); patches.push_back(p1); } }
// Eger esemenyeket lekezelo fuggveny void onMouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ // A GLUT_LEFT_BUTTON / GLUT_RIGHT_BUTTON illetve GLUT_DOWN / GLUT_UP float centreY = (float)((screenHeight / 2) - y) / (screenHeight / 2) * c.scale; float centerX = (float)(x - (screenWidth / 2)) / (screenWidth / 2) * c.scale; p.addControlPoint(ControlPoint(Vector(centerX, centreY), glutGet(GLUT_ELAPSED_TIME))); glutPostRedisplay(); // Ilyenkor rajzold ujra a kepet } }
ControlPoint CTrack::getItem( int i ) { if (i < CPs.size()) { return CPs[i]; } return ControlPoint("NO"); }
void CNewParticleEffect::RecordControlPointOrientation( int nWhichPoint ) { if ( m_bRecord && m_nToolParticleEffectId != TOOLPARTICLESYSTEMID_INVALID && clienttools->IsInRecordingMode() ) { // FIXME: Make a more direct way of getting QAngle angles; VectorAngles( ControlPoint( nWhichPoint ).m_ForwardVector, ControlPoint( nWhichPoint ).m_UpVector, angles ); static ParticleSystemSetControlPointOrientationState_t state; state.m_nParticleSystemId = GetToolParticleEffectId(); state.m_flTime = gpGlobals->curtime; state.m_nControlPoint = nWhichPoint; AngleQuaternion( angles, state.m_qOrientation ); KeyValues *msg = new KeyValues( "ParticleSystem_SetControlPointOrientation" ); msg->SetPtr( "state", &state ); ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg ); } }
ControlPoint Board::getOpenGlPosition(int x, int y) { float posX = 2.5 + 5*x; float posY = 0; float posZ = 2.5 + 5*y; return ControlPoint(posX, posY, posZ); }
void renormalizeImage(TVectorImage *vi) { int i, j; int n = vi->getStrokeCount(); std::vector<ControlPoint> points; points.reserve(n * 2); for (i = 0; i < n; i++) { TStroke *stroke = vi->getStroke(i); int m = stroke->getControlPointCount(); if (m > 0) { if (m == 1) points.push_back(ControlPoint(stroke, 0)); else { points.push_back(ControlPoint(stroke, 0)); points.push_back(ControlPoint(stroke, m - 1)); } } } int count = points.size(); for (i = 0; i < count; i++) { ControlPoint &pi = points[i]; TPointD posi = pi.getPoint(); TPointD center = posi; std::vector<int> neighbours; neighbours.push_back(i); for (j = i + 1; j < count; j++) { TPointD posj = points[j].getPoint(); double d = tdistance(posj, posi); if (d < 0.01) { neighbours.push_back(j); center += posj; } } int m = neighbours.size(); if (m == 1) continue; center = center * (1.0 / m); for (j = 0; j < m; j++) points[neighbours[j]].setPoint(center); } }
void sineTest( void ) { title = "Sine Test"; ControlPoint cp; cp = ControlPoint( Vector3(0.0, 0.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI/2.0, 1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI*3.0/2.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(2*PI, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(2*PI, 0.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); camera.position = Vector3( PI, 0.0, 6.0 ); camera.viewpoint = Vector3( PI, 0.0, 5.0 ); }
// get control point data through this method ControlPoint CTrack::getItem( Ogre::String tName ) { for (CPV::iterator ii = CPs.begin(); ii != CPs.end(); ii++) { ControlPoint a = *ii; if (a.name == tName) { return a; } } return ControlPoint("NO"); }
void Board::animate(int toX, int toY) { int positionX, positionY; std::string player_aux = currentPlayer; // find player position for(int i=0; i < 5; i++) { for (int j=0; j<5; j++) { if(board[i][j][0] == player_aux[0] && board[i][j][1] != '4') { positionX = i; positionY = j; } } } this->pieceToAnimate[0] = positionX; this->pieceToAnimate[1] = positionY; this->hasAnimation = true; this->animation = new LinearAnimation("animation", 0); ControlPoint initialPoint = this->getOpenGlPosition(positionX, positionY); ControlPoint finalPoint = this->getOpenGlPosition(toX, toY); ControlPoint initialPointHeight = ControlPoint(initialPoint.getX(), initialPoint.getY() + 10, initialPoint.getZ()); ControlPoint finalPointHeight = ControlPoint(finalPoint.getX(), finalPoint.getY() + 10, finalPoint.getZ()); this->animation->addControlPoint(initialPoint); this->animation->addControlPoint(initialPointHeight); this->animation->addControlPoint(finalPointHeight); this->animation->addControlPoint(finalPoint); this->animation->calculateTotalDistance(); //cout << positionX << " to " << toX << endl; //cout << positionY << " to " << toY << endl; }
//**************************************************************************** // // * The file format is simple // first line: an integer with the number of control points // other lines: one line per control point // either 3 (X,Y,Z) numbers on the line, or 6 numbers (X,Y,Z, orientation) //============================================================================ void CTrack:: readPoints(const char* filename) //============================================================================ { mDeleteAll(); FILE* fp = fopen(filename,"r"); if (!fp) { printf("Can't Open File!\n"); } else { char buf[512]; // first line = number of points fgets(buf,512,fp); size_t npts = (size_t) atoi(buf); if( (npts<4) || (npts>65535)) { printf("Illegal Number of Points Specified in File"); } else { CPs.clear(); // get lines until EOF or we have enough points while( (CPs.size() < npts) && fgets(buf,512,fp) ) { Ogre::Vector3 pos,orient; std::vector<const char*> words; breakString(buf,words); if (words.size() >= 3) { pos.x = (float) strtod(words[0],0); pos.y = (float) strtod(words[1],0); pos.z = (float) strtod(words[2],0); } else { pos.x=0; pos.y=0; pos.z=0; } if (words.size() >= 6) { orient.x = (float) strtod(words[3],0); orient.y = (float) strtod(words[4],0); orient.z = (float) strtod(words[5],0); } else { orient.x = 0; orient.y = 1; orient.z = 0; } orient.normalise(); mAdd(ControlPoint(pos,orient)); } } fclose(fp); } }
void lineTest( void ) { title = "Line Test"; ControlPoint cp; cp = ControlPoint( Vector3(-5.0, 0.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); cp = ControlPoint( Vector3(-5.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(5.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(5.0, 0.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); camera.position = Vector3( 0.0, 0.0, 10.0 ); camera.viewpoint = Vector3( 0.0, 0.0, 9.0 ); }
// the file format is simple // first line: an integer with the number of control points // other lines: one line per control point // either 3 (X,Y,Z) numbers on the line, or 6 numbers (X,Y,Z, orientation) void World::readPoints(const char* filename) { FILE* fp = fopen(filename,"r"); if (!fp) { fl_alert("Can't Open File!\n"); } else { char buf[512]; // first line = number of points fgets(buf,512,fp); size_t npts = (size_t) atoi(buf); if( (npts<4) || (npts>65535)) { fl_alert("Illegal Number of Points Specified in File"); } else { points.clear(); // get lines until EOF or we have enough points while( (points.size() < npts) && fgets(buf,512,fp) ) { Pnt3f pos,orient; vector<const char*> words; breakString(buf,words); if (words.size() >= 3) { pos.x = (float) strtod(words[0],0); pos.y = (float) strtod(words[1],0); pos.z = (float) strtod(words[2],0); } else { pos.x=0; pos.y=0; pos.z=0; } if (words.size() >= 6) { orient.x = (float) strtod(words[3],0); orient.y = (float) strtod(words[4],0); orient.z = (float) strtod(words[5],0); } else { orient.x = 0; orient.y = 1; orient.z = 0; } orient.normalize(); points.push_back(ControlPoint(pos,orient)); } } fclose(fp); } trainU = 0; }
static ControlPoint getControlPoint(const QList<ControlPoint> &selectedPoints, const ControlPoint &controlPoint, int indexOffset, bool isClosedPath) { int controlPointIndex = selectedPoints.indexOf(controlPoint); if (controlPointIndex >= 0) { int offsetIndex = controlPointIndex + indexOffset; if (offsetIndex >= 0 && offsetIndex < selectedPoints.count()) return selectedPoints.at(offsetIndex); else if (isClosedPath) { if (offsetIndex == -1) return selectedPoints.constLast(); else if (offsetIndex < selectedPoints.count()) return selectedPoints.at(1); } } return ControlPoint(); }
void immelmannTest( void ) { title = "Immelmann Test"; ControlPoint cp; cp = ControlPoint( Vector3(-1.0, -1.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); cp = ControlPoint( Vector3(-1.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(cos(PI/4), -sin(PI/4), 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(1.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(cos(PI/4), sin(PI/4), 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, 1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(-1.0, 1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(-1.0, 1.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); camera.position = Vector3( 0.0, 0.0, 3.0 ); camera.viewpoint = Vector3( 0.0, 0.0, 2.0 ); }
void compressedsineandsineTest( void ) { title = "Compressed Sine And Sine Test"; ControlPoint cp; cp = ControlPoint( Vector3(0.0, 0.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); // compressed amplitude sine cp = ControlPoint( Vector3(0.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI/4.0, 1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI*3/4.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); // remarked for better continuity over both catmullrom and bspline //cp = ControlPoint( Vector3(PI, 0.0, 0.0), CONTROL_POINT_MIDDLE ); //cplist.push_back(cp); // normal amplitude sine cp = ControlPoint( Vector3(PI+PI/2.0, 1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI+PI*3.0/2.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI+2*PI, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(PI+2*PI, 0.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); camera.position = Vector3( (PI+PI/2.0), 0.0, 8.0 ); camera.viewpoint = Vector3( (PI+PI/2.0), 0.0, 7.0 ); }
void Camera::computeReferenceFrame(Frame f, float time, ControlPoint nextTangent) { if (time == 0.0f) { count = 0; // calculate initial reference frame ref->T = f.tangent; ref->T.normalize(); ref->N = crossProduct(ControlPoint(0, 1, 0), ref->T); ref->N.normalize(); ref->B = crossProduct(ref->T, ref->N); ref->B.normalize(); } else if (f.isLast != 1) { ref->T = nextTangent; ref->T.normalize(); ref->N = crossProduct(ref->N, ref->T); ref->N.normalize(); ref->B = crossProduct(ref->T, ref->N); ref->B.normalize(); } }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(0); ofSetFrameRate(60); ofSetVerticalSync(true); ofSetDataPathRoot("../Resources/"); image.loadImage("gedou.jpg"); cols = image.width / blockSize; rows = image.height / blockSize; mesh.setMode(OF_PRIMITIVE_TRIANGLES); for (int y=0; y<rows; ++y) { for (int x=0; x<cols; ++x) { // 頂点 mesh.addVertex(ofVec3f(x*blockSize, y*blockSize, 0)); mesh.addVertex(ofVec3f((x+1)*blockSize, y*blockSize, 0)); mesh.addVertex(ofVec3f((x+1)*blockSize, (y+1)*blockSize, 0)); mesh.addVertex(ofVec3f((x+1)*blockSize, (y+1)*blockSize, 0)); mesh.addVertex(ofVec3f(x*blockSize, (y+1)*blockSize, 0)); mesh.addVertex(ofVec3f(x*blockSize, y*blockSize, 0)); // テクスチャ貼る mesh.addTexCoord(ofVec2f(x*blockSize, y*blockSize)); mesh.addTexCoord(ofVec2f((x+1)*blockSize, y*blockSize)); mesh.addTexCoord(ofVec2f((x+1)*blockSize, (y+1)*blockSize)); mesh.addTexCoord(ofVec2f((x+1)*blockSize, (y+1)*blockSize)); mesh.addTexCoord(ofVec2f(x*blockSize, (y+1)*blockSize)); mesh.addTexCoord(ofVec2f(x*blockSize, y*blockSize)); // デフォの位置を覚えておく 無駄、多いですけどね・・・ controlPoints.push_back(ControlPoint(x*blockSize, y*blockSize)); controlPoints.push_back(ControlPoint((x+1)*blockSize, y*blockSize)); controlPoints.push_back(ControlPoint((x+1)*blockSize, (y+1)*blockSize)); controlPoints.push_back(ControlPoint((x+1)*blockSize, (y+1)*blockSize)); controlPoints.push_back(ControlPoint(x*blockSize, (y+1)*blockSize)); controlPoints.push_back(ControlPoint(x*blockSize, y*blockSize)); } } ofSetWindowShape(image.width, image.height); status = VISIBLE; }
// Eger esemenyeket lekezelo fuggveny void onMouse(int button, int state, int x, int y) { //printf("%d,%d , katt\n", x, y); if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ // A GLUT_LEFT_BUTTON / GLUT_RIGHT_BUTTON illetve GLUT_DOWN / GLUT_UP glutPostRedisplay(); // Ilyenkor rajzold ujra a kepet //moved = false; } if (button == GLUT_LEFT_BUTTON && state == GLUT_UP){ //if (moved == false){ if (mouse.mouseStates != mouseMoving){ mouse.mouseLastUP = glutGet(GLUT_ELAPSED_TIME); mouse.mouseLastUP = mouse.mouseLastUP / 1000.0f; mouse.mouseStatesplus(); mouse.mouseLastStuff = ControlPoint(convertWinToGl(x, y), mouse.mouseLastUP); printf("%lf, %lf, katt gl\n", convertWinToGl(x, y).x, convertWinToGl(x, y).y); } else{//mouse.mouseStates = mouse.mouseMoving ban vagyunk //mozgat doMouse(); mouse.mouseStates = B0CLK; } } glutPostRedisplay(); }
void dblimmelmannTest( void ) { title = "Double Immelmann Test"; ControlPoint cp; // first immelmann cp = ControlPoint( Vector3(-2.0, -1.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); cp = ControlPoint( Vector3(-2.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, -1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(cos(PI/4), -sin(PI/4), 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(1.0, 0.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(cos(PI/4), sin(PI/4), 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, 1.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); // second immelmann cp = ControlPoint( Vector3(-cos(PI/4), 2.0-sin(PI/4), 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(-1.0, 2.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(-cos(PI/4), 2.0+sin(PI/4), 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(0.0, 3.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(2.0, 3.0, 0.0), CONTROL_POINT_MIDDLE ); cplist.push_back(cp); cp = ControlPoint( Vector3(2.0, 3.0, 0.0), CONTROL_POINT_END ); cplist.push_back(cp); camera.position = Vector3( 0.0, 1.0, 4.0 ); camera.viewpoint = Vector3( 0.0, 1.0, 3.0 ); }
Path::Path() { mControlPoints.resize(2); setFirstControlPoint(ControlPoint()); setLastControlPoint(ControlPoint()); mIsLooped = false; }
ControlPoint operator/(const ControlPoint& a, float c) { return ControlPoint(a.x / c, a.y / c, a.z / c); }
void addCP(Vector pos, float time){ if (numberOfPoints < 99){ points[numberOfPoints] = ControlPoint(pos + worldCenter, time); numberOfPoints++; } }
ControlPoint operator*(float c, const ControlPoint& a) { return ControlPoint(c * a.x, c * a.y, c * a.z); }
Path::Path() { setFirstControlPoint(ControlPoint()); setLastControlPoint(ControlPoint()); setLooped(false); }
ControlPoint operator+(const ControlPoint& a, const ControlPoint& b) { return ControlPoint(a.x + b.x, a.y + b.y, a.z + b.z); }