cpp_photon/test/Pen_test.cpp

99 lines
2.6 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.5 2005/07/20 06:12:13 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
class MainTask : public Task
{
public:
MainTask() :
Task("MainTask"),
app(AppCore::getInstance()),
video(video::VideoCore::getInstance())
{
video.setOrthoView(800,600);
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);
}
void update()
{
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;
AppCore& app;
video::VideoCore& video;
};
2005-07-19 20:55:40 +00:00
// standard application, creates window, registers task and runs
2005-07-17 06:19:08 +00:00
class PenTest : public Application
2005-07-17 05:38:44 +00:00
{
public:
int main(const StrVec& args)
{
AppCore::getInstance().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
2005-07-17 05:38:44 +00:00
Kernel::getInstance().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run();
return 0;
}
};
2005-07-17 06:19:08 +00:00
ENTRYPOINT(PenTest)