void startTest() { TCHAR logFileName[1024]; getLogFilename(logFileName); testLogFile = _tfopen(logFileName, _T("w")); if (!testLogFile) return; int pointTestErr = testPoint(); logHLine(); int vectorTestErr = testVector(); logHLine(); int lineTestErr = testLine(); logHLine(); int planeTestErr = testPlane(); logHLine(); int triangleTestErr = testTriangle(); logHLine(); int basisTestErr = testBasis(); logHLine(); int matrixTestErr = testMatrix(); fclose(testLogFile); testLogFile = NULL; }
void runIndexOfAfterTest(string const& inputStr, string const& testPtWKT) { GeomPtr input(reader.read(inputStr)); GeomPtr testPoint(reader.read(testPtWKT)); const Coordinate* testPt = testPoint->getCoordinate(); bool resultOK = indexOfAfterCheck(input.get(), *testPt); ensure(resultOK); }
void CMMFTestVideoPreProcHwDevice::SetOutputPadOptionsL(const TSize& aOutputSize, const TPoint& aPicturePos) { TSize testPad(KTestPadY, KTestPadX); TPoint testPoint(KTestPadPointY, KTestPadPointX); if (!(testPad == aOutputSize) || !(testPoint == aPicturePos)) User::Leave(KErrCorrupt); }
void ConvertEffectsTest::getTransformOriginPoint_percent_positive() { QImage img(testImg); effects.setImage(&img); QPoint testPoint(100, 50); PosUnitPair unitPair(Percent, Percent); QPoint expected(img.width(), img.height()/2); QPoint result = effects.getTransformOriginPoint(testPoint, unitPair); QCOMPARE(result, expected); }
void ConvertEffectsTest::getTransformOriginPoint_percent_zero() { QImage img(testImg); effects.setImage(&img); QPoint testPoint(0, 0); PosUnitPair unitPair(Percent, Percent); QPoint expected(testPoint); QPoint result = effects.getTransformOriginPoint(testPoint, unitPair); QCOMPARE(result, expected); }
bool ShadowVolumeBSP::testPoint(SVNode * root, const Point3F & pnt) { const PlaneF & plane = getPlane(root->mPlaneIndex); switch(plane.whichSide(pnt)) { case PlaneF::On: if(!root->mFront) return(true); else { if(testPoint(root->mFront, pnt)) return(true); else { if(!root->mBack) return(false); else return(testPoint(root->mBack, pnt)); } } break; // case PlaneF::Front: if(root->mFront) return(testPoint(root->mFront, pnt)); else return(true); break; // case PlaneF::Back: if(root->mBack) return(testPoint(root->mBack, pnt)); else return(false); break; } return(false); }
void ConvertEffectsTest::getTransformOriginPoint_percent_negative() { QImage img(testImg); effects.setImage(&img); QPoint testPoint(-10, -20); PosUnitPair unitPair(Percent, Percent); QPoint expected; expected.setX(-img.width()/10 + img.width()); expected.setY(-img.height()/5 + img.height()); QPoint result = effects.getTransformOriginPoint(testPoint, unitPair); QCOMPARE(result, expected); }
void ConvertEffectsTest::getTransformOriginPoint_pixels_negative_y() { QImage img(testImg); effects.setImage(&img); QPoint testPoint(100, -20); PosUnitPair unitPair(Pixel, Pixel); QPoint expected; expected.setX(testPoint.x()); expected.setY(testPoint.y() + img.height()); QPoint result = effects.getTransformOriginPoint(testPoint, unitPair); QCOMPARE(result, expected); }
void testGoodConstructor() { setUpFreetype( CHARACTER_CODE_A); TestGlyph testGlyph(face->glyph); FTPoint testPoint(47.0f, 0.0f, 0.0f); CPPUNIT_ASSERT( testPoint == testGlyph.Advance()); CPPUNIT_ASSERT_DOUBLES_EQUAL( 51.39, testGlyph.BBox().upperY, 0.01); CPPUNIT_ASSERT( testGlyph.Error() == 0); tearDownFreetype(); }
void runOffsetTest(string const& inputWKT, string const& testPtWKT, double offsetDistance, string const& expectedPtWKT) { GeomPtr input(reader.read(inputWKT)); GeomPtr testPoint(reader.read(testPtWKT)); GeomPtr expectedPoint(reader.read(expectedPtWKT)); const Coordinate* testPt = testPoint->getCoordinate(); const Coordinate* expectedPt = expectedPoint->getCoordinate(); Coordinate offsetPt = extractOffsetAt(input.get(), *testPt, offsetDistance); bool isOk = offsetPt.distance(*expectedPt) < TOLERANCE_DIST; if (! isOk) cout << "Expected = " << *expectedPoint << " Actual = " << offsetPt << endl; ensure(isOk); }
Frustum::Result Frustum::testBox (Vector3 box[8]) const { //Test against all planes for (int p=0; p<6; ++p) { int outCount = 0; //Test how many points is outside for (int b=0; b<8; ++b) if (testPoint( box[ b ], p ) == Frustum::Outside) outCount++; //The box is out if all points are outside any one of the planes if (outCount == 8) return Frustum::Outside; } return Frustum::Inside; }
int main(int argc, const char **argv) { printf("Running all tests...\n\n"); //**** core tests testTree(); testParse(); testDef(); testWord(); testFlow(); testVM(); testStack(); testInit(); testCommand(); testConversation(); testScape(); // testThreads(); //**** builtins tests testNoun(); testPattern(); //testArray(); // testStream(); testInt(); testStr255(); testCfunc(); testReceptorUtil(); // testReceptor(); //testVmHost(); //**** examples test testPoint(); // testLine(); report_tests(); return 0; }
void testConvexHullProjectionWithGravity() { // For this test, we will use a simple convex hull of side 1 meter // centered in the origin of the world and laying on the XY plane iDynTree::ConvexHullProjectionConstraint projectionConstraint; iDynTree::Polygon convexHull; convexHull.m_vertices.push_back(iDynTree::Position( 0.5, 0.5, 0.0)); convexHull.m_vertices.push_back(iDynTree::Position(-0.5, 0.5, 0.0)); convexHull.m_vertices.push_back(iDynTree::Position(-0.5, -0.5, 0.0)); convexHull.m_vertices.push_back(iDynTree::Position( 0.5, -0.5, 0.0)); std::vector<iDynTree::Polygon> polygons; polygons.resize(1); polygons[0] = convexHull; // The convex hull is already expressed in the world std::vector<iDynTree::Transform> transforms; transforms.push_back(iDynTree::Transform::Identity()); iDynTree::Direction xAxis(1.0, 0.0, 0.0); iDynTree::Direction yAxis(0.0, 1.0, 0.0); bool ok = projectionConstraint.buildConvexHull(xAxis,yAxis,iDynTree::Position::Zero(),polygons,transforms); ASSERT_IS_TRUE(ok); // Use a test position that is outside the convex hull with the normal projection iDynTree::Position testPoint(1.0, 0.0, 1.0); // Projected along the normal of the plane, this point is outside the convex hull // Note: positive margin means inside, negative outside ASSERT_IS_TRUE(projectionConstraint.computeMargin(projectionConstraint.project(testPoint)) < 0); //---------------------------------------------------------------------------------------------- // If the direction along which we are projecting is the normal of the plane, the projection // should match the one done without direction iDynTree::Direction planeNormal(0.0, 0.0, -1.0); projectionConstraint.setProjectionAlongDirection(planeNormal); ASSERT_EQUAL_VECTOR(projectionConstraint.project(testPoint), projectionConstraint.projectAlongDirection(testPoint)); //---------------------------------------------------------------------------------------------- // If the direction of the projection is "skewed" to the left, the point should instead be inside the convex hull iDynTree::Direction skewedDirection(-1.0, 0.0, -1.0); projectionConstraint.setProjectionAlongDirection(skewedDirection); std::cerr << projectionConstraint.computeMargin(projectionConstraint.projectAlongDirection(testPoint)) << std::endl; ASSERT_IS_TRUE(projectionConstraint.computeMargin(projectionConstraint.projectAlongDirection(testPoint)) > 0); //---------------------------------------------------------------------------------------------- // The code should work even if I try to project in the opposite direction wrt 'planeNormal' iDynTree::Direction upwardDirection(0.0, 0.0, 1.0); projectionConstraint.setProjectionAlongDirection(upwardDirection); // I should obtain the same result as the orthogonal projection ASSERT_EQUAL_VECTOR(projectionConstraint.project(testPoint), projectionConstraint.projectAlongDirection(testPoint)); // The projected point should be again outside the convex hull ASSERT_IS_TRUE(projectionConstraint.computeMargin(projectionConstraint.projectAlongDirection(testPoint))< 0); }
// Main entry point for the application void DarkGDK ( void ) { dbSyncOn ( ); dbSyncRate ( FRAMES_PER_SECOND ); dbSetWindowOff(); dbSetDisplayMode( SCREEN_WIDTH, SCREEN_HEIGHT, 16 ); dbDisableEscapeKey ( ); dbHideMouse(); dbSetImageColorKey ( 255, 0, 255 ); // Set transparency key for images dbDrawSpritesFirst(); // So that we can draw and write over sprites // Probably not necessary now since we don't actually use DGDK sprite objects dbLoadSound("bullet.wav",1); dbLoadSound("explosion.wav",2); // Load a new map Map *map = new Map(); bool gotmap = map->loadFromFile( "testmap.txt" ); assert( gotmap && "Loading map failed" ); // Set up a camera looking at our map Camera camera; camera.setMap( map ); camera.setScreenPosition( 10, 10 ); camera.setSize( 380, 480 ); // Camera2 Camera camera2; camera2.setMap( map ); camera2.setScreenPosition( 410, 10 ); camera2.setSize( 380, 480 ); camera2.getStateMachine()->changeState( CameraFollowWASDKeysState::getInstance() ); // Set up some enemies for( int i=0; i<NUM_TEST_ENEMIES; i++ ) { Enemy *enemy = new Enemy(); enemy->setPosition( Vector2D(rand()%SCREEN_WIDTH,rand()%SCREEN_HEIGHT) ); // Set up a test path Path *path = new Path(); path->addWaypoint( Vector2D(200.0,200.0) ); path->addWaypoint( Vector2D(400.0,300.0) ); path->addWaypoint( Vector2D(700.0,-30.0) ); path->setLooped(true); enemy->setPath( path ); // Create a new enemy using that path enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() ); //enemy->getStateMachine()->changeState( EnemyCollideWithPlayerState::getInstance() ); //entityManager.registerEntity( enemy ); MessageManager::getInstance()->dispatchMessage(0,0,messageCreateEntity,(i+1)*3,enemy); } dbPerformChecklistControlDevices(); if( dbChecklistString(1) ) dbSetControlDevice( dbChecklistString(1) ); char debugText[100]; // Set up variables to keep track of elapsed time double previousTime = (double)dbTimer(); double currentTime; double elapsedTime; // Set up the target Vector2D target; target.x = 400; target.y = 300; double timeSinceLastSpawn = 10.0; double timeBetweenSpawns = 2.0; bool spacePressedLastFrame = false; Vector2D testPosition(1.0,3.0); Vector2D testHeading(1.0,0.0); Vector2D testSide = testHeading.Perp(); Vector2D testPoint(-1.0,4.0); Vector2D testVector = TransformFromWorldToLocalSpace(testPoint,testHeading,testSide,testPosition); // main loop while ( LoopGDK ( ) ) { // Calculate elapsed time currentTime = (double)dbTimer(); elapsedTime = (currentTime - previousTime)/1000; previousTime = currentTime; MessageManager::getInstance()->update(elapsedTime); // Clear the screen white dbCLS( RGB( 0, 0, 0 ) ); camera.update( 0.0 ); //camera.draw(); camera2.update( 0.0 ); //camera2.draw(); // Spawn a new enemy for testing timeSinceLastSpawn += elapsedTime; if( timeSinceLastSpawn > timeBetweenSpawns ) { timeSinceLastSpawn = 0.0; entityManager.spawnRandomWave(); /* Enemy *enemy = new Enemy(Vector2D(100.0,-10.0)); // Set up a test path Path *path = new Path(); path->addWaypoint( Vector2D(200.0,200.0) ); path->addWaypoint( Vector2D(400.0,300.0) ); path->addWaypoint( Vector2D(700.0,-10.0) ); path->setLooped(false); enemy->setPath( path ); enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() ); entityManager.registerEntity( enemy ); */ } // Update and draw the enemies entityManager.updateAllEntities( elapsedTime ); entityManager.drawAllEntities(); // Reset the first entities position if( dbMouseClick() == 2 ) { Vector2D position( dbMouseX(), dbMouseY() ); Vector2D velocity( 0.0, -20.0 ); //Vector2D velocity = target - position; //velocity.Normalize(); //velocity *= 20.0; Bullet *bullet = new Bullet(position,velocity); entityManager.registerEntity( bullet ); } // Reset the enemies randomly if space pressed if( dbSpaceKey() && spacePressedLastFrame == false ) { spacePressedLastFrame = true; Enemy *enemy = new Enemy(); enemy->setPosition(Vector2D(100.0,-30.0)); // Set up a test path Path *path = new Path(); path->addWaypoint( Vector2D(200.0,200.0) ); path->addWaypoint( Vector2D(400.0,300.0) ); path->addWaypoint( Vector2D(700.0,-30.0) ); path->setLooped(false); enemy->setPath( path ); enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() ); entityManager.registerEntity( enemy ); } if( !dbSpaceKey() ) spacePressedLastFrame = false; // Update the target if( dbMouseClick() == 1 ) { target.x = dbMouseX(); target.y = dbMouseY(); } // Draw the target //DrawTarget( target ); // Put any debugging messages here //sprintf( debugText, "Key code: %d", dbScanCode() ); // For finding keyboard scan codes //sprintf( debugText, "Elapsed time: %f", elapsedTime ); //sprintf( debugText, "Entities: %d FPS: %d", entityManager.getSize(), dbScreenFPS() ); //sprintf( debugText, "%s", dbChecklistString (1) ); //sprintf( debugText, "JoystickY: %d", joystickY ); //sprintf( debugText, "FPS: %d", dbScreenFPS() ); sprintf( debugText, "Score: %d", entityManager.getPlayer()->getScore() ); //sprintf( debugText, "Player Position: %f,%f", entityManager.getPlayer()->getPosition().x, entityManager.getPlayer()->getPosition().y ); //sprintf( debugText, "VectorX: %f VectorY: %f", testVector.x, testVector.y ); //sprintf( debugText, "screenWidth: %d screenHeight: %d", dbScreenWidth(), dbScreenHeight() ); // Print out the debug text dbInk( RGB(0,0,255), RGB(255,255,255) ); dbText( 0, SCREEN_HEIGHT-20, debugText ); // Draw scanlines //drawScanlines(3); // break out if escape has been pressed if ( dbEscapeKey ( ) ) break; // update the contents of the screen dbSync ( ); } // and now everything is ready to return back to Windows return; }
bool Frustum::isVisiblePoint(const vec3f& p) { return testPoint(p) != InteractionState::OUTSIDE; }
void PlayState::update() { if (!m_gameOver) { //bool moving = false; m_PlayerPos.x += 0.25 + m_Continuous*(0.05); m_Run.setSpeed((int)((0.25 + m_Continuous*(0.05))*10)); //This is a really funny way to do this bool hit = false; if (m_AnimLock == 6) { if (m_Action == 1) { m_audMan.playStereoSample("hit1", m_PlayerPos.x, m_PlayerPos.y); } if (m_Action == 2) { m_audMan.playStereoSample("hit2", m_PlayerPos.x, m_PlayerPos.y); } if (m_Action == 3) { m_audMan.playStereoSample("hit3", m_PlayerPos.x, m_PlayerPos.y); } for (int i=0; i<MAX_AI; ++i) { if (testPoint(i)) { if (m_Action == 1) { m_Score += 1 + m_Continuous; } if (m_Action == 2) { m_Score += 1 + 2*m_Continuous; } if (m_Action == 3) { m_Score += 1 + 3*m_Continuous; } m_AIs[i].speed += 0.05; m_AIs[i].walking = false; m_AIs[i].run.setVisible(true); m_AIs[i].walk.setVisible(false); m_AIs[i].walk.setSpeed((int)(m_AIs[i].speed*20)); m_AIs[i].run.setSpeed((int)(m_AIs[i].speed*20)); hit = true; m_Continuous += 1; switch ((int)Gosu::random(1.0, 7.0)) { case 1: m_audMan.playStereoSample("hurt1", m_AIs[i].pos.x, m_AIs[i].pos.y); break; case 2: m_audMan.playStereoSample("hurt2", m_AIs[i].pos.x, m_AIs[i].pos.y); break; case 3: m_audMan.playStereoSample("hurt3", m_AIs[i].pos.x, m_AIs[i].pos.y); break; case 4: m_audMan.playStereoSample("hurt4", m_AIs[i].pos.x, m_AIs[i].pos.y); break; } } } if (!hit) { m_Continuous = 0; } } if (m_AnimLock == 0) { m_LPunch.setVisible(false); m_RPunch.setVisible(false); m_HButt.setVisible(false); m_Run.setVisible(true); m_Run.setFrame(0); m_AnimLock -= 1; }else{ m_AnimLock -= 1; } InputManager *iman = InputManager::getCurrentContext(); if (iman->query("Play.PunchLeft") == InputManager::actnBegin) { m_Action = 1; m_LPunch.setVisible(true); m_RPunch.setVisible(false); m_HButt.setVisible(false); m_Run.setVisible(false); m_LPunch.setFrame(0); m_AnimLock = 8; } if (iman->query("Play.PunchRight") == InputManager::actnBegin) { m_Action = 2; m_LPunch.setVisible(false); m_RPunch.setVisible(true); m_HButt.setVisible(false); m_Run.setVisible(false); m_RPunch.setFrame(0); m_AnimLock = 16; } if (iman->query("Play.HeadButt") == InputManager::actnBegin) { m_Action = 3; m_LPunch.setVisible(false); m_RPunch.setVisible(false); m_HButt.setVisible(true); m_Run.setVisible(false); m_HButt.setFrame(0); m_AnimLock = 32; } //Update camera focus m_Focus[0] = m_PlayerPos.x; m_Focus[1] = m_PlayerPos.y - 24.0; m_Idle.setX(m_PlayerPos.x); m_Idle.setY(m_PlayerPos.y); m_Run.setX(m_PlayerPos.x); m_Run.setY(m_PlayerPos.y); int c = Gosu::interpolate<int>(255, 50, m_PlayerPos.x/2000.0); Gosu::Color color(255, c, c); m_Run.setColorMod(color); m_LPunch.setColorMod(color); m_RPunch.setColorMod(color); m_HButt.setColorMod(color); double f = m_PlayerPos.x/2000.0; f = f*f; int a = Gosu::interpolate<int>(0, 250, f); Gosu::Color color2(a, 255, c, c); m_Aura->setColorMod(color2); m_Aura->setX(m_PlayerPos.x); m_Aura->setY(m_PlayerPos.y); m_LPunch.setX(m_PlayerPos.x); m_LPunch.setY(m_PlayerPos.y); m_RPunch.setX(m_PlayerPos.x); m_RPunch.setY(m_PlayerPos.y); m_HButt.setX(m_PlayerPos.x); m_HButt.setY(m_PlayerPos.y); for (int i=0; i<MAX_AI; ++i) { if (m_AIs[i].walking) m_AIs[i].pos.x += m_AIs[i].speed; else m_AIs[i].pos.x += m_AIs[i].speed * 2.5; m_AIs[i].walk.setX(m_AIs[i].pos.x); m_AIs[i].walk.setY(m_AIs[i].pos.y); m_AIs[i].run.setX(m_AIs[i].pos.x); m_AIs[i].run.setY(m_AIs[i].pos.y); } m_rendMan.setCamera( m_Focus[0], m_Focus[1], m_Zoom, m_Rot); m_rendMan.update(); m_Graph.update(); }else{ if (m_creditTimer < 1.0) m_creditTimer += 0.01; if (m_creditTimer >= 1.0) { m_creditTimer = 1.0; if (!m_showCredits) m_GameTime = (Gosu::milliseconds() - m_gameTimer)/1000; m_showCredits = true; } m_fade.setRed(255*(1.0-m_creditTimer)); m_fade.setGreen(255*(1.0-m_creditTimer)); m_fade.setBlue(255*(1.0-m_creditTimer)); } if (m_PlayerPos.x > 1800) { if (m_explosTimer < 1.0) m_explosTimer += 0.2; if (m_explosTimer >= 1.0) m_explosTimer = 1.0; m_fade.setAlpha(255*m_explosTimer); if (!m_gameOver) m_audMan.playStereoSample("explosion", m_PlayerPos.x, m_PlayerPos.y); m_gameOver = true; } }