cpp_photon/test/Pen_test.cpp

88 lines
2.4 KiB
C++
Raw Normal View History

2005-07-17 05:38:44 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Pen_test.cpp,v 1.9 2005/08/16 06:32:39 cozman Exp $
2005-07-17 05:38:44 +00:00
#include "photon.hpp"
using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
2005-07-17 05:38:44 +00:00
2005-08-08 06:37:10 +00:00
class MainState : public State
2005-07-17 05:38:44 +00:00
{
public:
2005-08-08 06:37:10 +00:00
MainState() :
app(Application::getInstance())
2005-07-17 05:38:44 +00:00
{
2005-07-19 20:55:40 +00:00
// initialize three pens, red, blue and green
2005-07-17 05:38:44 +00:00
r.setColor(255, 0, 0);
g.setColor(0, 255, 0);
b.setColor(0, 0, 255);
}
2005-08-08 06:37:10 +00:00
void render()
2005-07-17 05:38:44 +00:00
{
2005-07-19 20:55:40 +00:00
static const math::Point2 center(400, 300); // used for clock
2005-07-17 05:38:44 +00:00
unsigned int i,j; //used throughout demo
2005-07-19 20:55:40 +00:00
// draw points in a traveling sine curve
2005-07-20 03:58:54 +00:00
g.fillRect(math::Rect(math::Point2(0,0), 800, 100));
2005-07-19 20:55:40 +00:00
for(i=0; i < 800; i += 5)
2005-07-17 05:38:44 +00:00
{
2005-07-19 20:55:40 +00:00
scalar ang = math::degToRad(i+100*app.getTime());
r.drawPoint(math::Point2(i, 50+50*std::sin(ang) ));
2005-07-17 05:38:44 +00:00
}
2005-07-19 20:55:40 +00:00
// draw lines in a fancy pattern
for(i=100; i <= 200; i += 20)
2005-07-17 05:38:44 +00:00
{
2005-07-19 20:55:40 +00:00
for(j=100; j <= 200; j += 20)
2005-07-17 05:38:44 +00:00
{
g.drawLine(math::Point2(100,i), math::Point2(j, 200));
}
}
2005-07-19 20:55:40 +00:00
// draw circles to create a clock
2005-07-17 05:38:44 +00:00
b.fillCircle(math::Circle(center, 60));
g.drawCircle(math::Circle(center, 60));
g.drawCircle(math::Circle(center, 50));
2005-07-19 20:55:40 +00:00
// draw vector as clock hand
2005-07-17 05:38:44 +00:00
math::Vector2 clockHand;
clockHand.resolveDeg(50, 20*app.getTime());
r.drawVector(center, clockHand);
2005-07-19 20:55:40 +00:00
// draw rectangles to show Rect::calcIntersection in action
2005-07-17 05:38:44 +00:00
math::Rect rect1(math::Point2(500, 300), 200, 100);
math::Rect rect2(math::Point2(550, 375), 100, 200);
2005-07-20 03:58:54 +00:00
r.drawRect(rect1);
b.drawRect(rect2);
g.fillRect(rect1.calcIntersection(rect2));
2005-07-17 05:38:44 +00:00
}
private:
video::Pen r,g,b;
2005-08-08 06:37:10 +00:00
Application& app;
2005-07-17 05:38:44 +00:00
};
2005-08-08 06:37:10 +00:00
int PhotonMain(const StrVec& args)
2005-07-17 05:38:44 +00:00
{
Application& app(Application::getInstance());
app.createDisplay(800,600,32,0,0,false); // create window
2005-07-17 05:38:44 +00:00
2005-08-08 06:37:10 +00:00
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
2005-07-17 05:38:44 +00:00
app.setState<MainState>(); // register state and make active
app.run(); // run until finished
2005-08-08 06:37:10 +00:00
return 0;
}