Dwell actions PLEASE HELP!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
only1skingle
Posts: 25
Joined: Mon Sep 27, 2010 6:51 pm
Location: United Kingdom

Dwell actions PLEASE HELP!

Post by only1skingle »

hey,

I am trying to get a program to perform an action without a mouse key.

I have a box that follows the position of the mouse:

core::position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DRectangle(video::SColor(100,255,255,255),
core::rect<s32>(m.X-20, m.Y-20, m.X+20, m.Y+20));

And I also have a rectangle placed in the window of my program:

driver->draw2DRectangle(video::SColor(100,100,255,0),
core::rect<s32>(1000,200,1200,400));

What im trying to do is have the program turn the rectangle a vibrant red
(255,255,0,0) when the rectangle that follows the mouse is placed on top of the large rectangle in my window.

How would i write the code for this?

a statement or loop i am guessing, but i'm not too sure how to write it.

Any help or code given would be appreciated! :)

thanks

only1skingle
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Hey!
The class "rect" (Link) has at least a function that detects whether two rectangles intersect. See isRectCollided(...).

p.
beer->setMotivationCallback(this);
only1skingle
Posts: 25
Joined: Mon Sep 27, 2010 6:51 pm
Location: United Kingdom

Post by only1skingle »

Lovely,

thanks very much! :)
only1skingle
Posts: 25
Joined: Mon Sep 27, 2010 6:51 pm
Location: United Kingdom

Post by only1skingle »

sorry i have another question.

forgive me i'm not the smartes or greatest at programming or understanding it.

firstly what does this mean: template<class T> ??

also the code examples they give, how would i place that within my code as im guessing i can't just put the following:

bool irr::core::rect< T >::isRectCollided ( const rect< T > & other ) const [inline]

bool irr::core::rect< T >::isValid ( ) const [inline] .

thanks
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

This is called a "Template", meaning the class is defined "more general" and it's up to you to give it a specific data type (at compile time).
E.g.: In your case this could be a rectangle based on integers, floats, doubles and the like.

For example:

Code: Select all

core::rect<s32>(a, b, c, d)
creates a rectangle consisting of signed integer values (s32 or "int") where (a,b) is the upper right corner of the rect, c is the width and d the height.

You might wanna read through some examples as templates are a very integral part of the C++ programming language.
beer->setMotivationCallback(this);
only1skingle
Posts: 25
Joined: Mon Sep 27, 2010 6:51 pm
Location: United Kingdom

Post by only1skingle »

cheers :)
Post Reply