dynamic triangle selector problem

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

dynamic triangle selector problem

Post by blackMasoon »

Hello I'm trying to implement a dynamic triangle selector for hiding sunflare when it is covered by another object. That's why i tried to cast a ray between camera and sun and check if sth is between them in my update method. But I have a problm with triangle selector... What and haw shall I choose object from scene in update loop? I did this but probably because of nullpointer it crashess the app:

Code: Select all

core::vector3df start = cam->getAbsolutePosition();
	core::vector3df end = flare->getAbsolutePosition();
	core::triangle3df triangle;
	core::line3d<f32> line(start, end);
	core::array<scene::ISceneNode *> nodes;
	const scene::ISceneNode *hitNode;
	pManager->getSceneManager()->getSceneNodesFromType(scene::ESNT_ANIMATED_MESH, nodes);
	scene::ITriangleSelector *select = pManager->getSceneManager()->createTriangleSelector((IAnimatedMeshSceneNode*)nodes[0]);
		pManager->getSceneManager()->getSceneCollisionManager()->getCollisionPoint(
			line, select, end, triangle, hitNode);
		if(hitNode)
			flare->setVisible(true);
		else
			flare->setVisible(false);
Is there any better technique to implement that?
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

What do you mean by sun flare? Are you referring to a lens flare effect like this applied to the screen?

Image
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

well sun flare is this
Image


so i suppose he means lens flare..

and you have to initialize the hitNode to 0 or else it gets random address and chances are it won't be 0, that's why it crashes
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

I ment lens flare... I thought it's obvious :) I just want to manipulate with its visibility when sun is behind something. The flare has same position as sun cause sun is a parent node for lens flare in my project.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I'm making a space game and I'll probably have solar flares, so I was just checking. :P

At a glance, couldn't you check the result of getCollisionPoint() directly? It returns a boolean value of if it there was a collision or not.

So what you want is to display the flare when sun isn't behind something? It becomes problematic fairly quickly, because I'd imagine the collision detection would be pretty expensive. Also, what if half of the sun is showing? Do you want the lens flare to appear with half transparency?

I'm not quite sure what other approaches you could use. I'll try to think of some and get back to you.
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

Well as we all know it is fixed in many games somehow :P That is why I was asking if there's a better solution for that... Speaking about those cases when f.ex half of sun is visible... The best way would be to throw the lens flare idea away and implement godrays :P Bt that would be probably hard using Irrlicht ;) Explaining if sun is visible or not by picking its center would be fine solution for me... I know that this may be an expensive solution but can't find any better right now :/

EDIT:

Anyway I started to search where the app crashes with my solution and it is here:

Code: Select all

scene::ITriangleSelector *select = pManager->getSceneManager()->createTriangleSelector((IAnimatedMeshSceneNode*)nodes[0]);
I don't know why... Whole code is in the first post.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Check for the size of nodes, maybe you didn't get any nodes returned.
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
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

Well that's hard to say, but I have a lot of nodes of this type in the scene. Is there any better way of selecting them than this one? Having an array and catching only the first one may be not a good idea but I don't know how to check the whole scene with all of its nodes by the selector...
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

It's not hard to say or even test - nodes is an array and has a size() function. Just check that.
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
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

It crashes even when I try to get scene node from id... Is there any way to use getCollisionPoint() method without defining triangle selector for specified node but for whole scene? That would fix the problem...
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

use meta triangle selector and add everything into it
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
PI
Posts: 176
Joined: Tue Oct 09, 2007 7:15 pm
Location: Hungary

Post by PI »

@entity: It'll be slow 'coz it'll just cycle through all of the selectors and check their BB (best case: checks only their BB) one by one. But yeah it's the easiest way!
Post Reply