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:
|
2005-08-10 21:22:33 +00:00
|
|
|
// $Id: Pen_test.cpp,v 1.8 2005/08/10 21:22:33 cozman Exp $
|
2005-07-17 05:38:44 +00:00
|
|
|
|
|
|
|
#include "photon.hpp"
|
|
|
|
using namespace photon;
|
2005-07-20 06:12:13 +00:00
|
|
|
#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
|
|
|
{
|
2005-08-08 06:37:10 +00:00
|
|
|
// create window
|
|
|
|
Application::getInstance().createDisplay(800,600,32,0,0,false);
|
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
|
|
|
|
2005-08-08 06:37:10 +00:00
|
|
|
// set current state
|
2005-08-10 21:22:33 +00:00
|
|
|
Application::getInstance().setState<MainState>();
|
2005-07-17 05:38:44 +00:00
|
|
|
|
2005-08-08 06:37:10 +00:00
|
|
|
// run until finished
|
|
|
|
Kernel::getInstance().run();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|