예제 #1
0
Point Robot::getBackRight() const
{
	// x and y are pointing to top left now
	int x = position.x - (size.x / 2);
	int y = position.y - (size.y / 2);

	Point originalBackRight( x + size.x, y + size.y);

	double angle = Shape2DUtils::getAngle( front) + 0.5 * PI;

	Point backRight( (originalBackRight.x - position.x) * std::cos( angle) - (originalBackRight.y - position.y) * std::sin( angle) + position.x, (originalBackRight.y - position.y) * std::cos( angle)
										+ (originalBackRight.x - position.x) * std::sin( angle) + position.y);

	return backRight;
}
예제 #2
0
void Pyramid::createPyramid()
{
	//Vertices
	Vect apex(0.0f, 7.07f, 0.0f);
	Vect frontLeft(-5.0f, 0.0f, 5.0f);
	Vect frontRight(5.0f, 0.0f, 5.0f);
	Vect backLeft(-5.0f, 0.0f, -5.0f);
	Vect backRight(5.0f, 0.0f, -5.0f);

	//Normals
	Vect frontNormal = (frontRight - frontLeft).cross(apex - frontRight);
	Vect rightNormal = (backRight - frontRight).cross(apex - backRight);
	Vect backNormal = (backLeft - backRight).cross(apex - backLeft);
	Vect leftNormal = (frontLeft - backLeft).cross(apex - frontLeft);
	Vect bottomNormal1 = (frontLeft - frontRight).cross(backLeft - frontLeft);
	Vect bottomNormal2 = (backRight - backLeft).cross(frontRight - backRight);

	pyramidBatch.Begin(GL_TRIANGLES, 18, 1);

	//Front side of pyramid
	//Front left
	pyramidBatch.Normal3f(frontNormal[x], frontNormal[y], frontNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	pyramidBatch.Vertex3f(frontLeft[x], frontLeft[y], frontLeft[z]);

	//Front right
	pyramidBatch.Normal3f(frontNormal[x], frontNormal[y], frontNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
	pyramidBatch.Vertex3f(frontRight[x], frontRight[y], frontRight[z]);

	//Apex
	pyramidBatch.Normal3f(frontNormal[x], frontNormal[y], frontNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.5f, 1.0f);
	pyramidBatch.Vertex3f(apex[x], apex[y], apex[z]);

	//Right side of pyramid
	//Front right
	pyramidBatch.Normal3f(rightNormal[x], rightNormal[y], rightNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	pyramidBatch.Vertex3f(frontRight[x], frontRight[y], frontRight[z]);

	//Back right
	pyramidBatch.Normal3f(rightNormal[x], rightNormal[y], rightNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
	pyramidBatch.Vertex3f(backRight[x], backRight[y], backRight[z]);

	//Apex
	pyramidBatch.Normal3f(rightNormal[x], rightNormal[y], rightNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.5f, 1.0f);
	pyramidBatch.Vertex3f(apex[x], apex[y], apex[z]);

	//Back side of pyramid
	//Back right
	pyramidBatch.Normal3f(backNormal[x], backNormal[y], backNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	pyramidBatch.Vertex3f(backRight[x], backRight[y], backRight[z]);

	//Back left
	pyramidBatch.Normal3f(backNormal[x], backNormal[y], backNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
	pyramidBatch.Vertex3f(backLeft[x], backLeft[y], backLeft[z]);

	//Apex
	pyramidBatch.Normal3f(backNormal[x], backNormal[y], backNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.5f, 1.0f);
	pyramidBatch.Vertex3f(apex[x], apex[y], apex[z]);

	//Left side of pyramid
	//Back left
	pyramidBatch.Normal3f(leftNormal[x], leftNormal[y], leftNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	pyramidBatch.Vertex3f(backLeft[x], backLeft[y], backLeft[z]);

	//Front left
	pyramidBatch.Normal3f(leftNormal[x], leftNormal[y], leftNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
	pyramidBatch.Vertex3f(frontLeft[x], frontLeft[y], frontLeft[z]);

	//Apex
	pyramidBatch.Normal3f(backNormal[x], backNormal[y], backNormal[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.5f, 1.0f);
	pyramidBatch.Vertex3f(apex[x], apex[y], apex[z]);

	//Bottom 1 of pyramid
	//Front right
	pyramidBatch.Normal3f(bottomNormal1[x], bottomNormal1[y], bottomNormal1[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
	pyramidBatch.Vertex3f(frontRight[x], frontRight[y], frontRight[z]);

	//Front left
	pyramidBatch.Normal3f(bottomNormal1[x], bottomNormal1[y], bottomNormal1[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	pyramidBatch.Vertex3f(frontLeft[x], frontLeft[y], frontLeft[z]);

	//Back left
	pyramidBatch.Normal3f(bottomNormal1[x], bottomNormal1[y], bottomNormal1[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
	pyramidBatch.Vertex3f(backLeft[x], backLeft[y], backLeft[z]);

	//Bottom 2 of pyramid
	//Back left
	pyramidBatch.Normal3f(bottomNormal2[x], bottomNormal2[y], bottomNormal2[z]);
	pyramidBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
	pyramidBatch.Vertex3f(backLeft[x], backLeft[y], backLeft[z]);

	//Back right
	pyramidBatch.Normal3f(bottomNormal2[x], bottomNormal2[y], bottomNormal2[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
	pyramidBatch.Vertex3f(backRight[x], backRight[y], backRight[z]);

	//Front right
	pyramidBatch.Normal3f(bottomNormal2[x], bottomNormal2[y], bottomNormal2[z]);
	pyramidBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
	pyramidBatch.Vertex3f(frontRight[x], frontRight[y], frontRight[z]);

	pyramidBatch.End();
}
예제 #3
0
파일: cb.c 프로젝트: AnmolMago/Vex-Robotics
task main3(){
	nMotorEncoder[armLeft2] = 0;
	nMotorEncoder[armRight2] = 0;
	//either for play
			//flipout();
	//or for testing
			SensorValue[claw] = open;//close claw
			wait1Msec(1000);//wait
	intake();
	wait1Msec(250);
	armUp(250);//arm up just enough
	wait1Msec(20);//wait
	backRight(350*1.6);//first turn towards goal
	right(175*1.6);//second turn towards goal
	armDown(0);
	wait1Msec(750);//wait
	SensorValue[claw] = open;//open claw
	wait1Msec(100);//wait
	backLeft(175*1.6);//turn 1
	wait1Msec(50);//wait
	left(350*1.6);//turn     2

	SensorValue[claw] = open;//close claw
	wait1Msec(1000);//wait
	intake();
	wait1Msec(250);
	armUp(250);//arm up just enough
	wait1Msec(20);//wait
	backRight(350*1.6);//first turn towards goal
	right(200*1.6);//second turn towards goal
	armDown(0);
	wait1Msec(750);//wait
	SensorValue[claw] = open;//open claw
	wait1Msec(100);//wait
	backLeft(160*1.6);//turn 1
	wait1Msec(50);//wait
	left(350*1.6);//turn     2

	SensorValue[claw] = open;//close claw
	wait1Msec(1000);//wait
	intake();
	wait1Msec(250);
	armUp(250);//arm up just enough
	wait1Msec(20);//wait
	backRight(350*1.6);//first turn towards goal
	right(200*1.6);//second turn towards goal
	armDown(0);



	/*wait1Msec(1000);//wait
	intake();
	wait1Msec(20);//wait .02 sec (future: is because this small thing stops bot from carrying its previous momentum forward)
	armUp(200);//arm up just enough
	wait1Msec(20);//wait
	backRight(225);//first turn towards goal
	right(235);//second turn towards goal
	wait1Msec(500);//wait
	armDown(0);
	SensorValue[claw] = 0;//open claw
	wait1Msec(500);//wait
	armUp(150);
	wait1Msec(20);//wait
	backLeft(200);//turn 1
	armDown(160);
	wait1Msec(50);//wait
	left(325);//turn     2

	///REPEAT EVERYTHING

	/*wait1Msec(750);//wait
	SensorValue[claw] = 1;//close claw
	wait1Msec(20);//wait .02 sec (future: because this small thing stops bot from carrying its previous momentum forward)
	armUp(250);//arm up just enough
	wait1Msec(20);//wait
	//backRight(250);//first turn towards goal
	//right(225);//second turn towards goal
	backRight(275);//first turn towards goal
	right(175);//second turn towards goal
	wait1Msec(250);//wait
	armDown(250);
	SensorValue[claw] = 0;//open claw
	wait1Msec(500);//wait
	armUp(150);
	wait1Msec(20);//wait
	backLeft(225);
	armDown(150);
	wait1Msec(50);//wait
	left(300);

	///REPEAT EVERYTHING
	wait1Msec(750);//wait*/
}
예제 #4
0
파일: main.cpp 프로젝트: jcb1996/Game
int main()
{
    //Create window, and limit frame rate
    sf::RenderWindow window (sf::VideoMode(800, 600, 32), "Game", sf::Style::Default);
    window.setFramerateLimit(60);

//------------------------TEXTURES------------------------------

    //Declare textures
    sf::Texture texture;
    sf::Texture texture1;
    sf::Texture texture2;
    //Load image
    if(!texture.loadFromFile("Sprites/main.png"))
    {
        return 1;
    }
    if(!texture1.loadFromFile("Sprites/background.png"))
    {
        return 1;
    }
    if(!texture2.loadFromFile("Sprites/house.png"))
    {
        return 1;
    }

//------------------------SPRITES--------------------------

    //Creates and places the sprites
    sf::Sprite sprite;
    sf::Sprite background;
    sf::Sprite house;
    sprite.setPosition(400, 300);
    background.setPosition(0, 0);
    house.setPosition(440, 300);

    //Loads texture into sprite
    sprite.setTexture(texture);
    background.setTexture(texture1);
    house.setTexture(texture2);

//-------------------------RECTANGLES--------------------------------

    //Declares the rectangles
    sf::IntRect front(1, 1, 18, 24);
    sf::IntRect back (20, 1, 18, 24);
    sf::IntRect left (20, 26, 18, 24);
    sf::IntRect right (1, 26, 18, 24);
    //Steps
    sf::IntRect frontLeft(39, 1, 18, 24);
    sf::IntRect frontRight(39, 26, 18, 24);
    sf::IntRect backLeft();
    sf::IntRect backRight();
    sf::IntRect leftLeft();
    sf::IntRect leftRight();
    sf::IntRect rightLeft();
    sf::IntRect rightRight();

    sf::IntRect backgroundRect (0, 0, 800, 600);

    sf::IntRect houseRect (0, 0, 17, 22);


    //Crop sprites using rectangles defined above
    sprite.setTextureRect(front);
    background.setTextureRect(backgroundRect);
    house.setTextureRect(houseRect);

//-----------------------SOUND------------------------------------------------------

    //Declare the Sound Buffer
    sf::SoundBuffer footstepsBuffer;
    sf::SoundBuffer bumpBuffer;
    //Loads the sound file
    if(!footstepsBuffer.loadFromFile("Sounds/footsteps.wav"))
    {
        return 1;
    }
    if(!bumpBuffer.loadFromFile("Sounds/bump.wav"))
    {
        return 1;
    }

    //Declare sound
    sf::Sound footsteps;
    sf::Sound bump;
    //Load Buffer into Sound
    footsteps.setBuffer(footstepsBuffer);
    bump.setBuffer(bumpBuffer);

//-------------------------------MAIN-----------------------------

    //Main window loop
    while(window.isOpen())
    {
        sf::Event event;

        //Vectors used for collision
        sf::Vector2i spritePosition(sprite.getPosition());
        sf::Vector2i backgroundPosition(background.getPosition());
        sf::Vector2i housePosition(house.getPosition());

        //Sprite Vectors
        sf::Vector2i backVector(back.width, back.height);
        sf::Vector2i frontVector(front.width, front.height);
        sf::Vector2i rightVector(right.width, right.height);
        sf::Vector2i leftVector(left.width, left.height);

        //House Vectors
        sf::Vector2i houseVector(houseRect.width, houseRect.height);

        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            if(event.key.code == sf::Keyboard::Insert)
            {
                sf::Image screenshot = window.capture();
                screenshot.saveToFile("Screenshot.png");
            }
        }

//-----------------------------------MOVEMENT----------------------------------------

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            //Change to stepping sprite
            Sleep(250);
            sprite.setTextureRect(back);
            sprite.move(0, -24);
            //Redeclaring the collision textures
            sf::Vector2i spritePosition(sprite.getPosition());
            sf::Vector2i housePosition(house.getPosition());
            if(collision(spritePosition, backVector, housePosition, houseVector) == true)
            {
                sprite.move(0, 24);
                bump.play();
            }
            else
            {
                footsteps.play();
            }
        }

        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            //Change to stepping sprite
            Sleep(250);
            sprite.setTextureRect(front);
            sprite.move(0, 24);
            //Redeclaring the collision textures
            sf::Vector2i spritePosition(sprite.getPosition());
            sf::Vector2i housePosition(house.getPosition());
            if(collision(spritePosition, frontVector, housePosition, houseVector) == true)
            {
                sprite.move(0, -24);
                bump.play();
            }
            else
            {
                footsteps.play();
            }
        }

        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            //Change to stepping sprite
            Sleep(250);
            sprite.setTextureRect(right);
            sprite.move(19, 0);
            //Redeclaring the collision textures
            sf::Vector2i spritePosition(sprite.getPosition());
            sf::Vector2i housePosition(house.getPosition());
            if(collision(spritePosition, leftVector, housePosition, houseVector) == true)
            {
                sprite.move(-19, 0);
                bump.play();
            }
            else
            {
                footsteps.play();
            }
        }

        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            //Change to stepping sprite
            Sleep(250);
            sprite.setTextureRect(left);
            sprite.move(-19, 0);
            //Redeclaring the collision textures
            sf::Vector2i spritePosition(sprite.getPosition());
            sf::Vector2i housePosition(house.getPosition());
            if(collision(spritePosition, rightVector, housePosition, houseVector) == true)
            {
                sprite.move(19, 0);
                bump.play();
            }
            else
            {
                footsteps.play();
            }
        }

        //Draw sequence
        window.clear(); //(Red, Green, Blue, (optional) Alpha) Alpha is transperency

        //Draw....

        window.draw(background);

        window.draw(house);

        window.draw(sprite);

        window.display();

        std::cout << x << std::endl;
        std::cout << y << std::endl;
    }
    return 0;
}