#include #include "IrrLib.h" #include using namespace std; using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; int main(){ IrrLib Irrlicht(5, 640, 480, 16, false, true, false); //Create a variable to determine if we should draw under the mouse or not bool draw = false; //Screen caption std::string cap; //Future use of screen resolution dimension2d res; //Declare 2 mouse containters so we can find out if the user has moved the mouse position2d mxy; position2d lastmxy; //This function returns the size of the window Irrlicht is currently using res = Irrlicht.GetScreenSize(); //Set the caption cap = "Height in pixels: " + Irrlicht.int_to_string(res.Height) + " Width in pixels: " + Irrlicht.int_to_string(res.Width); Irrlicht.SetWindowCaption(Irrlicht.stdstring_to_stringw(cap)); while (Irrlicht.DeviceIsRunning()) if (Irrlicht.IsActiveWindow()) { //I was in a Red color mood when I made this, you can chose from a varity of colors. Irrlicht.BeginScene(Irrlicht.Color.RED); //If the user hits the left mouse button if (Irrlicht.IrrEvent.mouseStates[0]) { //we need to set it to false so we don't detect it again Irrlicht.IrrEvent.mouseStates[0] = false; //The user clicked the mouse so we need to turn drawing on and record the mouse //pos so we can find out later if they move the mouse if (draw == false){ lastmxy.Y = Irrlicht.IrrEvent.getMouseY(); lastmxy.X = Irrlicht.IrrEvent.getMouseX(); draw = true; } else //turn it off draw = false; } //if drawing is on if (draw) { //Get current mouse pos mxy.Y = Irrlicht.IrrEvent.getMouseY(); mxy.X = Irrlicht.IrrEvent.getMouseX(); //If current mouse pos != last mouse pos then add the line to Irr2D's vector of lines //So Irr2D will know how many lines to draw and where to draw them //Also record this pos so we can compare it later if (mxy != lastmxy){ Irrlicht.Irr2DLib.AddLines(lastmxy, mxy, Irrlicht.Color.GREEN); lastmxy = mxy; } } //This is new, this tells Irr2D to draw all lines that it has collected so far Irrlicht.Irr2DLib.DrawLines(); //The usual stuff Irrlicht.DrawAll(); Irrlicht.EndScene(); } Irrlicht.EndIrrlicht(); return 0; }