Beam scenenode
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Are you bleeping serious? You'll have to call setStartPoint() with your ships's position (from getAbsolutePosition()), and setEndPoint() with where you want it to end.
If you ask how you calculate the end point, I'm coming for you with a cheese grater and a jar of battery acid.
If you ask how you calculate the end point, I'm coming for you with a cheese grater and a jar of battery acid.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
instead ofempirepro wrote:How can I get this to shoot from my ship instead of a set location?
Code: Select all
beam->SetStartPoint( core::vector3df( -500, 0, 0 ) );
Code: Select all
beam->SetStartPoint( shipMesh->getPosition());
Here is my BeamSceneNode. Works better then the one showed at the beginning.
Header:
Source:
Usage:
Header:
Code: Select all
#ifndef CBEAMSCENENODE_H
#define CBEAMSCENENODE_H
#include <irrlicht.h>
namespace irr
{
namespace scene
{
class CBeamNode : public ISceneNode
{
public:
private:
// The beam material.
video::SMaterial material;
video::SMaterial material2;
// Bounding Box
core::aabbox3d<f32> Box;
core::vector3df m_start;
core::vector3df m_end;
f32 m_thickness;
public:
CBeamNode( scene::ISceneNode* parent, scene::ISceneManager *mgr, s32 id, char* szBeam , char* szBeamFront );
~CBeamNode(void);
virtual void OnRegisterSceneNode(void);
virtual void OnAnimate(u32 timeMs);
virtual void render(void);
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual u32 getMaterialCount();
virtual video::SMaterial& getMaterial(u32 i);
void setLine(core::vector3df start, core::vector3df end, f32 thickness);
};
}
}
#endif
Code: Select all
#include "CBeamSceneNode.h"
namespace irr
{
namespace scene
{
CBeamNode::CBeamNode( ISceneNode* parent, ISceneManager *mgr, s32 id, char* szBeam , char* szBeamFront ) : ISceneNode( parent, mgr, id )
{
// Setup the beam material
material.Wireframe = false;
material.Lighting = false;
//material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
//material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
material.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
material.Textures[0] = mgr->getVideoDriver( )->getTexture( szBeam );
//material.Textures[1] = mgr->getVideoDriver( )->getTexture( szBeam );
material2.Wireframe = false;
material2.Lighting = false;
//material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
//material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
material2.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
material2.Textures[0] = mgr->getVideoDriver( )->getTexture( szBeamFront );
m_thickness = 1.0f;
}
CBeamNode::~CBeamNode(void)
{
}
void CBeamNode::OnRegisterSceneNode(void)
{
ISceneNode::OnRegisterSceneNode();
}
void CBeamNode::OnAnimate(u32 timeMs)
{
if ( IsVisible )
{
SceneManager->registerNodeForRendering( this );
}
ISceneNode::OnAnimate(timeMs);
}
void CBeamNode::setLine(core::vector3df start, core::vector3df end, f32 thickness)
{
m_start = start;
m_end = end;
m_thickness = thickness;
}
void CBeamNode::render(void)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(irr::video::ETS_WORLD, AbsoluteTransformation);
core::vector3df direction = m_end-m_start;
direction.normalize();
core::vector3df savesatrt = m_start;
AbsoluteTransformation.transformVect(savesatrt);
core::vector3df lookdir = savesatrt-SceneManager->getActiveCamera()->getAbsolutePosition();
if(lookdir.getLength() < 20)
return;
lookdir.normalize();
core::vector3df view(SceneManager->getActiveCamera()->getTarget() - SceneManager->getActiveCamera()->getAbsolutePosition());
view.normalize();
if(lookdir.dotProduct(direction)/(lookdir.getLength()*direction.getLength()) < .98f && lookdir.dotProduct(direction)/(lookdir.getLength()*direction.getLength()) > -.98f)
{
core::vector3df updown = direction.crossProduct(lookdir);
updown.normalize();
core::vector3df normal = direction.crossProduct(updown);
video::S3DVertex vertices[4];
u16 indices[] = {0,1,2,1,3,2};
vertices[0] = video::S3DVertex(m_end-updown*m_thickness*0.5f, normal, video::SColor(255,255,255,255), core::vector2d<f32>(0,0));
vertices[1] = video::S3DVertex(m_end+updown*m_thickness*0.5f, normal, video::SColor(255,255,255,255), core::vector2d<f32>(0,1));
vertices[2] = video::S3DVertex(m_start-updown*m_thickness*0.5f, normal, video::SColor(255,255,255,255), core::vector2d<f32>(1,0));
vertices[3] = video::S3DVertex(m_start+updown*m_thickness*0.5f, normal, video::SColor(255,255,255,255), core::vector2d<f32>(1,1));
driver->setMaterial(material);
driver->drawIndexedTriangleList(&vertices[0], 4, &indices[0], 2);
//driver->draw3DLine(m_start, m_end, video::SColor(255,255,0,0));
}
else
{
//printf("daw dot\n");
core::vector3df horizontal = SceneManager->getActiveCamera()->getUpVector().crossProduct(view);
horizontal.normalize();
horizontal *= 0.5f * m_thickness;
core::vector3df vertical = horizontal.crossProduct(view);
vertical.normalize();
vertical *= 0.5f * m_thickness;
view *= -1.0f;
video::S3DVertex vertices[4];
u16 indices[] = {0,1,2,1,3,2};
vertices[0] = video::S3DVertex(m_end - horizontal - vertical, view, video::SColor(255,255,255,255), core::vector2d<f32>(0,0));
vertices[1] = video::S3DVertex(m_end + horizontal - vertical, view, video::SColor(255,255,255,255), core::vector2d<f32>(0,1));
vertices[2] = video::S3DVertex(m_end - horizontal + vertical, view, video::SColor(255,255,255,255), core::vector2d<f32>(1,0));
vertices[3] = video::S3DVertex(m_end + horizontal + vertical, view, video::SColor(255,255,255,255), core::vector2d<f32>(1,1));
driver->setMaterial(material2);
driver->drawIndexedTriangleList(&vertices[0], 4, &indices[0], 2);
}
}
const core::aabbox3d<f32>& CBeamNode::getBoundingBox() const
{
return Box;
}
u32 CBeamNode::getMaterialCount()
{
return 2;
}
video::SMaterial& CBeamNode::getMaterial(u32 i)
{
if(i==0)
return material;
else if(i==1)
return material2;
}
}
}
Code: Select all
scene::CBeamSceneNode* beam = new scene::CBeamNode(parent, smgr, -1, "The texture the beam should have when looking at it from the side , "The texture when looking at the cap" );
//now set the beam
beam->setLine(core::vector3df(0,0,0), core::vector3df(10,10,10), 5.0f);
beam->drop();
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
maybe u could show some code and tell us what exactly is not working.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Pennies to pounds he's shooting beams directly away from the camera position.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
ahh ok that should work with my beamscenenode when u set the start position a litle bit infront of the camera (farther then the near clipping plane) then u should see a dot bc u can only se th cap of the beam.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Oh, I've just taken a good look at your code. That's a nice way of doing it: much better than cross polys. Thanks for sharing.Sudi wrote:ahh ok that should work with my beamscenenode when u set the start position a litle bit infront of the camera (farther then the near clipping plane) then u should see a dot bc u can only se th cap of the beam.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Yes, but like a comic at a charity gig, you don't generally give away your A material.Sudi wrote:no problem thats what the forum is for
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 226
- Joined: Fri Aug 22, 2008 8:50 pm
- Contact: