How to build walls?

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
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

How to build walls?

Post by wsw1231 »

I am wondering if Irrlicht engine can handle the case in which the user clicks the left-mouse button and drags and drops to create a rectangular selection.

For example,
Image

My question is how I can draw this rectangular selection? I think it should be drawn in another scene manager, shouldn't it?
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

The rectangle in the above picture is in XY plane.
How can I change it to XZ plane when the user drags and drops the mouse?
CuteAlien
Admin
Posts: 9693
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You can use ISceneCollisionManager ::getRayFromScreenCoordinates to create a ray which you can then collide against a plane to get a point in 3D. The plane basically sets the height at which you want that ray to collide so in your case it will probably have normal vector pointing upwards and a d value of your height (usually the y of your floor-height).

Some example code here how to use getRayFromScreenCoordinates: http://irrlicht.sourceforge.net/phpBB2/ ... oordinates
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
_maxim_
Posts: 54
Joined: Thu May 27, 2010 11:05 am
Location: Russia
Contact:

Post by _maxim_ »

here is my not finished game constructor http://kolosov.ath.cx/pyge.zip
walls drawing with mouse as plane mesh on grid
source is python script, but it is similar c++
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

CuteAlien wrote:You can use ISceneCollisionManager ::getRayFromScreenCoordinates to create a ray which you can then collide against a plane to get a point in 3D. The plane basically sets the height at which you want that ray to collide so in your case it will probably have normal vector pointing upwards and a d value of your height (usually the y of your floor-height).

Some example code here how to use getRayFromScreenCoordinates: http://irrlicht.sourceforge.net/phpBB2/ ... oordinates
Thanks for your advice.
But how are the lines drawn? How to represent the rectangle? Which API should be used?

Now, I can get the starting and ending 3D points of the selection. I would like to represent the wall by a cube with a certain texture.

So, you can imagine that I have already selected a plane in planeXZ after dragging& dropping the left mouse button, how can I set the wall which has its bottom y-value = that planeXZ.y value? And how to set the wall height based on the bottom?
Last edited by wsw1231 on Sat Mar 05, 2011 8:43 am, edited 1 time in total.
_maxim_
Posts: 54
Joined: Thu May 27, 2010 11:05 am
Location: Russia
Contact:

Post by _maxim_ »

wsw1231 wrote:But how are the lines drawn? How to represent the rectangle? Which API should be used?
IVideoDriver->draw3DLine(vector3d<f32> start, vector3d<f32> end) see my link above

IVideoDriver->draw2DRectangle(SColor, rect<s32>(X1, Y1, X2, Y2))
from 2DGraphics example 6
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

_maxim_ wrote:
wsw1231 wrote:But how are the lines drawn? How to represent the rectangle? Which API should be used?
IVideoDriver->draw3DLine(vector3d<f32> start, vector3d<f32> end) see my link above

IVideoDriver->draw2DRectangle(SColor, rect<s32>(X1, Y1, X2, Y2))
from 2DGraphics example 6
Would draw3DBox() be better?
Because in my case, the selection is on the planeXZ, so it is reasonable to make the selection rectangle to be 3D but with y-value = 0.

But I am not sure how to use that API :(

Edit:
OK, I think draw3DBox can do if I set the box minEdge and maxEdge y values to 0.

But can I fill alpha color to the 3D Box?
_maxim_
Posts: 54
Joined: Thu May 27, 2010 11:05 am
Location: Russia
Contact:

Post by _maxim_ »

Yes, better choice.
This code draw rectangle, sorry for python

Code: Select all

device = createDevice(EDT_OPENGL, dimension2du(640, 480))
driver = device.getVideoDriver()
smgr = device.getSceneManager()
camera = smgr.addCameraSceneNodeFPS()
camera.setPosition(vector3df(50,200,50))
m = SMaterial()
m.Lighting = False
matrix = matrix4()
while device.run():
	driver.beginScene(True, True, SColor(255,0,0,255))
	driver.setMaterial(m)# for valid color
	driver.setTransform(ETS_WORLD, matrix)# for valid detection 3d coords
	driver.draw3DBox(aabbox3df(0,0,0,100,0,100), SColor(128,255,0,0))
	smgr.drawAll()
	driver.endScene()
device.drop()
alpha change has no effect for me, perhaps must be first change line width
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

_maxim_ wrote:Yes, better choice.
This code draw rectangle, sorry for python

Code: Select all

device = createDevice(EDT_OPENGL, dimension2du(640, 480))
driver = device.getVideoDriver()
smgr = device.getSceneManager()
camera = smgr.addCameraSceneNodeFPS()
camera.setPosition(vector3df(50,200,50))
m = SMaterial()
m.Lighting = False
matrix = matrix4()
while device.run():
	driver.beginScene(True, True, SColor(255,0,0,255))
	driver.setMaterial(m)# for valid color
	driver.setTransform(ETS_WORLD, matrix)# for valid detection 3d coords
	driver.draw3DBox(aabbox3df(0,0,0,100,0,100), SColor(128,255,0,0))
	smgr.drawAll()
	driver.endScene()
device.drop()
alpha change has no effect for me, perhaps must be first change line width
Thanks for your code. I will try it later.

For the alpha color, I think you misunderstood my meaning. I would like to apply alpha color to the selection region instead of the border of the selection region. That means what I am asking is how to fill alpha color to that aabbox3d
Post Reply