ObjectNode* genBranch(int branching, int maxDepth, int density, float scaleFactor, float seasonProb, const mat4& initTrans, const mat4& initSkew, int currentDepth) { mat4 tempTrans = distort(0.2, 1.0, 0.2); mat4 tempMove = translate(0.0, 1.0, 0.0); mat4 tempSkew = distort(5.0, 1.0, 5.0); mat4 tempRotate = rX(M_PI/2.0); ObjectNode* branch = new ObjectNode(nullptr, initTrans, initSkew); branch->addChild(*new ObjectNode( Global::treeCone, tempMove * tempTrans * tempRotate, tempSkew * tempRotate ) ); if (currentDepth < maxDepth) { const int branchFact = branching; mat4 tempRotate = rZ(M_PI/6.0); mat4 rotMat = rY(2.0 * M_PI / branchFact); tempTrans = scale(scaleFactor); tempMove = translate(0.0, 1.5, 0.0); mat4 twist = rY(M_PI / branchFact) * tempMove; mat4 loopTemp = rotMat * tempRotate; for (int i = 0; i < branchFact; ++i) { loopTemp = rotMat * loopTemp; branch->addChild( *genBranch( branching, maxDepth, density, scaleFactor, seasonProb, twist * loopTemp * tempTrans, loopTemp, currentDepth + 1 ) ); } } return branch; }
ObjectNode* genHouseOut(const mat4& initTrans, const mat4& initSkew) { ObjectNode* house = new ObjectNode(nullptr, initTrans, initSkew); const float height = 0.5; house->addChild( *new ObjectNode( Global::houseCube, translate(0.0, -height, 0.0) * distort(1.0, 0.01, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(0.0, 0.0, -1.0) * distort(1.0, height, 0.01) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(1.0, 0.0, 0.0) * distort(0.01, height, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(-1.0, 0.0, 0.0) * distort(0.01, height, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(0.58, 0.0, 1.0) * distort(0.42, height, 0.01) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(-0.58, 0.0, 1.0) * distort(0.42, height, 0.01) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(0.0, 0.35, 1.0) * distort(0.25, 0.3 * height, 0.01) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(-0.29, -0.16, 1.13) * rY(M_PI/4.0) * distort(0.2, 0.7 * height, 0.01), rY(M_PI/4.0) ) ); house->addChild( *new ObjectNode( Global::housePyramid, translate(0.0, 0.85, 0.0) * scale(1.7) * distort(1.0, 0.2, 1.0) * rY(M_PI/4.0) * rX(M_PI/2.0), distort(1.0, 5.0, 1.0) * rY(M_PI/4.0) * rX(M_PI/2.0) ) ); return house; }
ObjectNode* genTree(int branching, int maxDepth, int density, float scaleFactor, float seasonProb, float height, const mat4& initTrans, const mat4& initSkew) { ObjectNode* tree = new ObjectNode(nullptr,initTrans, initSkew); mat4 tempRotate = rX(M_PI/2.0); mat4 tempTrans = distort(1.0, 0.2, 1.0); mat4 tempSkew = distort(1.0, 5.0, 1.0); mat4 tempMove = translate(0.0, -2.0, 0.0); tree->addChild( *new ObjectNode( Global::treeCone, tempMove * tempTrans * tempRotate, tempSkew * tempRotate) ); tempTrans = distort(0.3, height, 0.3); tempMove[1][3] = height - 2.0; tree->addChild( *new ObjectNode(Global::treeCylinder, tempMove * tempTrans * tempRotate, tempRotate) ); tempMove[1][3] = height * 0.6 + 0.1; tree->addChild( *genBranch(branching, maxDepth, density, scaleFactor, seasonProb, tempMove) ); mat4 rotMat = rY(2.0 * M_PI/4.0); tempSkew = rZ(M_PI/4.0); for (int i = 0; i < 4; ++i) { tempSkew = rotMat * tempSkew; tree->addChild( *genBranch(branching, maxDepth, density, scaleFactor, seasonProb, tempMove * tempSkew, tempSkew) ); } tree->addChild( *genLeafBunch(M_PI/2.0, 3.0, 0.5, density, translate(0.0, height, 0.0) * scale(0.7)) ); return tree; }
bool isCollision( std::vector<Room> & rooms, uint32_t x, uint32_t y, uint32_t w, uint32_t h ) { for( std::vector<Room>::iterator rIter = rooms.begin(), end = rooms.end() ; rIter != end ; ++rIter ) { uint32_t & rX( rIter->x ); uint32_t & rY( rIter->y ); uint32_t & rW( rIter->w ); uint32_t & rH( rIter->h ); bool roomOkay; if( (rX + rW + 1 ) < x || rX > (x + w + 1 ) ) { roomOkay = true; } else if( (rY + rH + 1) < y || rY > (y + h + 1 ) ) { roomOkay = true; } else { roomOkay = false; } if( !roomOkay ) { return true; } } return false; }
EnvironmentNode* genHouseIn(const mat4& initTrans, const mat4& initSkew) { EnvironmentNode* house = new EnvironmentNode(BoolState(1u, 0u), initTrans, initSkew); house->addChild( *new LightNode(Lightsource("pointLight", false), translate(0.0, -0.35, -0.87)) ); const float height = 0.5; house->addChild( *new ObjectNode(Global::houseSquare, translate(0.0, -height + 0.02, 0.0) * rX(M_PI/2.0), rX(M_PI/2.0) ) ); house->addChild( *new ObjectNode(Global::houseSquare, translate(0.0, height - 0.02, 0.0) * rX(M_PI/2.0), rX(M_PI/2.0) ) ); house->addChild( *new ObjectNode( Global::houseSquare, translate(0.0, 0.0, -0.98) * distort(1.0, height, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseSquare, translate(0.98, 0.0, 0.0) * distort(1.0, height, 1.0) * rY(M_PI/2.0), rY(M_PI/2.0) ) ); house->addChild( *new ObjectNode( Global::houseSquare, translate(-0.98, 0.0, 0.0) * distort(1.0, height, 1.0) * rY(M_PI/2.0), rY(M_PI/2.0) ) ); house->addChild( *new ObjectNode( Global::houseSquare, translate(0.58, 0.0, 0.98) * distort(0.42, height, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseSquare, translate(-0.58, 0.0, 0.98) * distort(0.42, height, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseSquare, translate(0.0, 0.35, 0.98) * distort(0.25, 0.3 * height, 1.0) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(-0.2, 0.0, 0.6) * distort(0.01, height, 0.4) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(0.2, 0.0, 0.6) * distort(0.01, height, 0.4) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(-0.75, 0.0, 0.2) * distort(0.25, height, 0.01) ) ); house->addChild( *new ObjectNode( Global::houseCube, translate(0.75, 0.0, 0.2) * distort(0.25, height, 0.01) ) ); house->addChild( *genFirePlace( translate(0.0, -0.35, -0.95) * distort(1.5, 1.25, 0.2) * scale(0.25) )); house->addChild( *genBed(translate(-0.5, -0.37, 0.85) * scale(0.3)) ); house->addChild( *genBed(translate(0.65, -0.37, 0.85) * scale(0.3)) ); house->addChild( *genChair(translate(-0.3, -0.4, -0.35) * rY(M_PI/4.0) * scale(0.2), rY(M_PI/4.0)) ); house->addChild( *genChair(translate(0.25, -0.4, -0.3) * rY(M_PI/2.0) * scale(0.2), rY(M_PI/2.0)) ); house->addChild( *genChair(translate(0.8, -0.4, -0.4) * rY(M_PI) * distort(1.0, 1.0, 3.0) * scale(0.2), rY(M_PI)) ); return house; }
ObjectNode* genForest(int numTrees, float minR, float maxR, const mat4& initTrans, const mat4& initSkew) { ObjectNode* forest = new ObjectNode(nullptr, initTrans, initSkew); mat4 rotMat = rY(0.3 * numTrees + 2.0 * M_PI / numTrees); mat4 tempPosit = MatMath::ID; for (int i = 0; i < numTrees; ++i, rotMat *= rotMat) { tempPosit = rotMat * translate(0.0, 0.0, -randNum(minR, maxR)); forest->addChild( *genTree( 3, 2, 150, 0.5, 0.5, 1.6, tempPosit, tempPosit ) ); } return forest; }
ObjectNode* genLeafBunch(float rho, float radius, float prob, int numLeaves, const mat4& initTrans, const mat4& initSkew) { ObjectNode* bunch = new ObjectNode(nullptr, initTrans, initSkew); mat4 rotMat = MatMath::ID; mat4 tempTrans = translate(0.0, radius, 0.0); mat4 tempRotate = rY( randNum(0.0, 2.0 * M_PI) ) * rZ(randNum(0.0, rho) ); ObjectNode* temp = new ObjectNode(nullptr, tempRotate * tempTrans, tempRotate); temp->addChild(*genLeaf(prob)); bunch->addChild(*temp); for (int i = 1; i < numLeaves; ++i) { rotMat = rY( randNum(0.0, 2.0 * M_PI) ) * rX( randNum(0.0, M_PI/2.0) ); tempRotate = rY( randNum(0.0, 2.0 * M_PI) ) * rX( randNum(0.0, rho) ); temp = new ObjectNode(nullptr, tempRotate * tempTrans * rotMat, tempRotate * rotMat); temp->addChild(*genLeaf(prob)); bunch->addChild(*temp); } return bunch; }
// This test is mainly for coverage purposes. void TestDumpState() { // Create a VanDerPol system VanDerPolOde ode_system; // Dump the state variables std::string state = ode_system.DumpState("This is a test."); TS_ASSERT_EQUALS(state, "This is a test.\nState:\n\tx:10 m\n\tv:10 m/s\n"); // Dump user-supplied values std::vector<double> rY(2); rY[0] = 0.0; rY[1] = 1.0; state = ode_system.DumpState("Test 2.", rY, 0); TS_ASSERT_EQUALS(state, "Test 2.\nAt independent variable (usually time) = 0\nState:\n\tx:0 m\n\tv:1 m/s\n"); state = ode_system.DumpState("Test 2.", rY); TS_ASSERT_EQUALS(state, "Test 2.\nState:\n\tx:0 m\n\tv:1 m/s\n"); }
void mouseMotion(int p, int q) //rotates the camera if the left mouse button is pressed down. //assumes user is clicking and pulling on a plane parallel to the projection plane, //and approximates the angle of rotation by using the sphere tangent to that plane. //for the plane at z = -1, that is the unit sphere, along Global::which all arcs are equal //to the angle that subtends them, meaning that the distance moved by the mouse //along the tangent plane can be directly plugged in as the angle of rotation { if (Global::leftMouse) { float delta_p = 3.0 * Global::FOV * (M_PI/180.0) * (p - Global::pRef) / Global::viewDim; float delta_q = 2.5 * Global::FOV * (M_PI/180.0) * (q - Global::qRef) / Global::viewDim; mat4 delta_yaw = rY(delta_p); Global::pitchTheta = (Global::pitchTheta + delta_q > -M_PI/2.0 && Global::pitchTheta + delta_q < M_PI/2.0) ? Global::pitchTheta + delta_q : Global::pitchTheta; Global::yawMat = delta_yaw * Global::yawMat; Global::positMat = delta_yaw * Global::positMat; Global::pitchMat = rX(Global::pitchTheta); Global::pRef = p, Global::qRef = q; glutPostRedisplay(); } }
mat4 driveCar(float theta) { return rY(theta); }