Exemple #1
0
void ParticleSystemProxy::simulateNoHeightmap()
{
    int timediff = int(GUIEngine::getLatestDt() * 1000.f);
    int active_count = getEmitter()->getMaxLifeTime() * getEmitter()->getMaxParticlesPerSecond() / 1000;
    core::matrix4 matrix = getAbsoluteTransformation();
    glUseProgram(ParticleShader::SimpleSimulationShader::Program);
    glEnable(GL_RASTERIZER_DISCARD);

    glUniform1i(ParticleShader::SimpleSimulationShader::uniform_dt, timediff);
    glUniform1i(ParticleShader::SimpleSimulationShader::uniform_level, active_count);
    glUniformMatrix4fv(ParticleShader::SimpleSimulationShader::uniform_sourcematrix, 1, GL_FALSE, matrix.pointer());
    glUniform1f(ParticleShader::SimpleSimulationShader::uniform_size_increase_factor, size_increase_factor);

    glBindVertexArray(current_simulation_vao);
    glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_buffers[1]);

    glBeginTransformFeedback(GL_POINTS);
    glDrawArrays(GL_POINTS, 0, count);
    glEndTransformFeedback();
    glBindVertexArray(0);

    glDisable(GL_RASTERIZER_DISCARD);
    std::swap(tfb_buffers[0], tfb_buffers[1]);
    std::swap(current_rendering_vao, non_current_rendering_vao);
    std::swap(current_simulation_vao, non_current_simulation_vao);
}
Exemple #2
0
ccBBox ccGBLSensor::getOwnBB(bool withGLFeatures/*=false*/)
{
	if (!withGLFeatures)
	{
		return ccBBox();
	}

	//get sensor position
	ccIndexedTransformation sensorPos;
	if (!getAbsoluteTransformation(sensorPos,m_activeIndex))
	{
		return ccBBox();
	}

	ccPointCloud cloud;
	if (!cloud.reserve(8))
	{
		//not enough memory?!
		return ccBBox();
	}

	cloud.addPoint(CCVector3(-m_scale,-m_scale,-m_scale));
	cloud.addPoint(CCVector3(-m_scale,-m_scale, m_scale));
	cloud.addPoint(CCVector3(-m_scale, m_scale,-m_scale));
	cloud.addPoint(CCVector3(-m_scale, m_scale, m_scale));
	cloud.addPoint(CCVector3( m_scale,-m_scale,-m_scale));
	cloud.addPoint(CCVector3( m_scale,-m_scale, m_scale));
	cloud.addPoint(CCVector3( m_scale, m_scale,-m_scale));
	cloud.addPoint(CCVector3( m_scale, m_scale, m_scale));

	cloud.applyRigidTransformation(sensorPos);
	return cloud.getOwnBB(false);
}
Exemple #3
0
/*
void AnimObject::setSelector(irr::scene::ISceneManager *gSceneManager, irr::scene::ITriangleSelector *selector)
{
	selector = gSceneManager->createTriangleSelector(_node);
	setTriangleSelector(selector);
	selector->drop();
}


void AnimObject::drop()
{
	getMesh()->drop();
	drop();
}

void AnimObject::setMaterial(ITexture *texture)
{
	setMaterialFlag(EMF_LIGHTING, true);
	setMaterialTexture(0, texture);
}

void AnimObject::setPosition(vector3df position)
{
	setPosition(position);
	_billboard->setPosition(position + vector3df(0, 15, 0));
}

void AnimObject::setRotation(vector3df rotation)
{
	setRotation(rotation);
}

void AnimObject::setScale(vector3df scale)
{
	setScale(scale);
}

// Gets
*/
vector3df AnimObject::getDirection()
{
	matrix4 transf = getAbsoluteTransformation();
	vector3df dir = vector3df(0.0f, 0.0f, 1.0f);
	transf.rotateVect(dir);
	return dir;
}
Exemple #4
0
void Camera::updateMatrices()
{
	math::Vector3f position = getAbsolutePosition();
	math::Vector3f rotation = getAbsoluteTransformation().getRotationDegrees();

	view.buildFirstPersonCameraMatrix(position, rotation);
}
	void CLightSceneNode::doLightRecalc()
	{
		if ((LightData.Type == ELT_SPOT) || (LightData.Type == ELT_DIRECTIONAL))
		{
			LightData.Direction = Vector3(.0f, .0f, 1.0f);
			//getAbsoluteTransformation().rotateVect(LightData.Direction);
			Matrix4 mat = getAbsoluteTransformation();
			LightData.Direction = mat.rotateVect(LightData.Direction);
			LightData.Direction.normalize();
		}
		if ((LightData.Type == ELT_SPOT) || (LightData.Type == ELT_POINT))
		{ 
			const FLOAT32 r = LightData.Radius * LightData.Radius * 0.5f;
			//BBox.MaxEdge.set(r, r, r);
			//BBox.MinEdge.set(-r, -r, -r);
			BBox.setMaximum(Vector3(r, r, r));
			BBox.setMinimum(Vector3(-r, -r, -r));
			//setAutomaticCulling( scene::EAC_BOX );
			setAutomaticCulling(EAC_OFF);
			LightData.Position = getAbsolutePosition();
		}
		if (LightData.Type == ELT_DIRECTIONAL)
		{
			BBox.reset(Vector3(0, 0, 0));
			setAutomaticCulling(EAC_OFF);
		}
	}
Exemple #6
0
	void EngineExhaustNode::OnAnimate(u32 timeMs)
	{
		ISceneNode::OnAnimate(timeMs);

		auto vec = mExhaustVelocity;
		getAbsoluteTransformation().rotateVect(vec);

		for(auto fire : mFireEmitters )
		{
			fire->getEmitter()->setDirection( vec + mShipVelocity );
		}
	}
Exemple #7
0
void ParticleSystemProxy::simulateHeightmap()
{
	int timediff = int(GUIEngine::getLatestDt() * 1000.f);
	int active_count = getEmitter()->getMaxLifeTime() * getEmitter()->getMaxParticlesPerSecond() / 1000;
	core::matrix4 matrix = getAbsoluteTransformation();
	glUseProgram(HeightmapSimulationShader::Program);
	glEnable(GL_RASTERIZER_DISCARD);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_position);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_lifetime);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_velocity);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_size);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[0]);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_position, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)0);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_lifetime, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(3 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_velocity, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(4 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_size, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(7 * sizeof(float)));
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_position);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_lifetime);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_velocity);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_size);
	glBindBuffer(GL_ARRAY_BUFFER, initial_values_buffer);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_position, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)0);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_lifetime, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(3 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_velocity, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(4 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_size, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(7 * sizeof(float)));
	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_buffers[1]);

	glUniform1i(HeightmapSimulationShader::uniform_dt, timediff);
	glUniform1i(HeightmapSimulationShader::uniform_level, active_count);
	glUniformMatrix4fv(HeightmapSimulationShader::uniform_sourcematrix, 1, GL_FALSE, matrix.pointer());
	glUniform1f(HeightmapSimulationShader::uniform_size_increase_factor, size_increase_factor);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_BUFFER, heightmaptexture);
	glUniform1i(HeightmapSimulationShader::uniform_heightmap, 2);
	glUniform1f(HeightmapSimulationShader::uniform_track_x, track_x);
	glUniform1f(HeightmapSimulationShader::uniform_track_z, track_z);
	glUniform1f(HeightmapSimulationShader::uniform_track_x_len, track_x_len);
	glUniform1f(HeightmapSimulationShader::uniform_track_z_len, track_z_len);

	glBeginTransformFeedback(GL_POINTS);
	glDrawArrays(GL_POINTS, 0, count);
	glEndTransformFeedback();
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_position);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_lifetime);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_velocity);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_size);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_position);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_lifetime);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_velocity);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_size);
	glDisable(GL_RASTERIZER_DISCARD);
	std::swap(tfb_buffers[0], tfb_buffers[1]);
}
Exemple #8
0
ccBBox ccGBLSensor::getOwnFitBB(ccGLMatrix& trans)
{
	//get sensor position
	ccIndexedTransformation sensorPos;
	if (!getAbsoluteTransformation(sensorPos,m_activeIndex))
		return ccBBox();

	trans = sensorPos;

	return ccBBox(	CCVector3(-m_scale,-m_scale,-m_scale),
					CCVector3( m_scale, m_scale, m_scale) );
}
//! does nothing.
void CGameParticleContainerSceneNode::render()
{
	IVideoDriver *driver = getIView()->getDriver();

	#ifdef GSEDITOR
	CGameObject::EObjectState state = m_owner->getObjectState();
	
	// draw bbox on select
	if (
			state == CGameObject::Move ||
			state == CGameObject::Review		
		)
		setDebugDataVisible( EDS_BBOX );
	else
		setDebugDataVisible( 0 );

	// call object draw
	m_owner->drawObject();

#endif
	
	if ( DebugDataVisible & scene::EDS_BBOX )
	{		
		driver->setTransform(video::ETS_WORLD, getAbsoluteTransformation() );
		video::SMaterial deb_m;
		deb_m.Lighting = false;
		driver->setMaterial(deb_m);
		
		driver->draw3DBox( Box, video::SColor(255,255,255,255));
	}

#ifdef GSEDITOR	
	// draw move
	if ( 
			state == CGameObject::Move || 
			state == CGameObject::Rotation ||
			state == CGameObject::Scale
		)
		m_owner->drawFrontUpLeftVector();	
	
	if ( state == CGameObject::Rotation )
		m_owner->drawCircleAroundObject();	
#endif

}
//! does nothing.
void CGameContainerSceneNode::render()
{
	if ( m_owner == NULL )
		return;

	IVideoDriver *driver = getIView()->getDriver();

	if ( DebugDataVisible & scene::EDS_BBOX )
	{
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		video::SMaterial deb_m;
		deb_m.Lighting = false;
		driver->setMaterial(deb_m);

		core::aabbox3d<f32> tbox = Box;
		getAbsoluteTransformation().transformBoxEx(tbox);

		driver->draw3DBox( tbox, video::SColor(255,255,0,255));
	}
}
void CLightSceneNode::doLightRecalc()
{
	if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_DIRECTIONAL))
	{
		LightData.Direction = core::vector3df(.0f,.0f,1.0f);
		getAbsoluteTransformation().rotateVect(LightData.Direction);
		LightData.Direction.normalize();
	}
	if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_POINT))
	{
		const f32 r = LightData.Radius * LightData.Radius * 0.5f;
		BBox.MaxEdge.set( r, r, r );
		BBox.MinEdge.set( -r, -r, -r );
		setAutomaticCulling( scene::EAC_BOX );
		LightData.Position = getAbsolutePosition();
	}
	if (LightData.Type == video::ELT_DIRECTIONAL)
	{
		BBox.reset( 0, 0, 0 );
		setAutomaticCulling( scene::EAC_OFF );
	}
}
//! pre render event
void CBillboardTextSceneNode::OnAnimate(u32 timeMs)
{
	if (!IsVisible || !Font || !Mesh)
		return;

	ICameraSceneNode* camera = SceneManager->getActiveCamera();
	if (!camera)
		return;

	// get text width
	f32 textLength = 0.f;
	u32 i;
	for(i=0; i!=Symbol.size(); ++i)
	{
		SSymbolInfo &info = Symbol[i];
		textLength += info.Kerning + info.Width;
	}
	if (textLength<0.0f)
		textLength=1.0f;

	//const core::matrix4 &m = camera->getViewFrustum()->Matrices[ video::ETS_VIEW ];

	// make billboard look to camera
	core::vector3df pos = getAbsolutePosition();

	core::vector3df campos = camera->getAbsolutePosition();
	core::vector3df target = camera->getTarget();
	core::vector3df up = camera->getUpVector();
	core::vector3df view = target - campos;
	view.normalize();

	core::vector3df horizontal = up.crossProduct(view);
	if ( horizontal.getLength() == 0 )
	{
		horizontal.set(up.Y,up.X,up.Z);
	}

	horizontal.normalize();
	core::vector3df space = horizontal;

	horizontal *= 0.5f * Size.Width;

	core::vector3df vertical = horizontal.crossProduct(view);
	vertical.normalize();
	vertical *= 0.5f * Size.Height;

	view *= -1.0f;

	// center text
	pos += space * (Size.Width * -0.5f);

	for ( i = 0; i!= Symbol.size(); ++i )
	{
		SSymbolInfo &info = Symbol[i];
		f32 infw = info.Width / textLength;
		f32 infk = info.Kerning / textLength;
		f32 w = (Size.Width * infw * 0.5f);
		pos += space * w;

		SMeshBuffer* buf = (SMeshBuffer*)Mesh->getMeshBuffer(info.bufNo);

		buf->Vertices[info.firstVert+0].Normal = view;
		buf->Vertices[info.firstVert+1].Normal = view;
		buf->Vertices[info.firstVert+2].Normal = view;
		buf->Vertices[info.firstVert+3].Normal = view;

		buf->Vertices[info.firstVert+0].Pos = pos + (space * w) + vertical;
		buf->Vertices[info.firstVert+1].Pos = pos + (space * w) - vertical;
		buf->Vertices[info.firstVert+2].Pos = pos - (space * w) - vertical;
		buf->Vertices[info.firstVert+3].Pos = pos - (space * w) + vertical;

		pos += space * (Size.Width*infk + w);
	}

	// make bounding box

	for (i=0; i< Mesh->getMeshBufferCount() ; ++i)
		Mesh->getMeshBuffer(i)->recalculateBoundingBox();
	Mesh->recalculateBoundingBox();

	BBox = Mesh->getBoundingBox();
	core::matrix4 mat( getAbsoluteTransformation(), core::matrix4::EM4CONST_INVERSE );
	mat.transformBoxEx(BBox);
}
void CGameColladaContainerSceneNode::render()
{
	if (m_owner == NULL)
		return;	

#ifdef GSEDITOR
	CGameObject::EObjectState state = m_owner->getObjectState();
	
	// draw bbox on select
	if ( 
			state == CGameObject::Move ||
			state == CGameObject::Review
		)
		setDebugDataVisible( EDS_BBOX );
	else
		setDebugDataVisible( 0 );

	// call object draw
	m_owner->drawObject();	

	// draw bouding box
	if ( DebugDataVisible & scene::EDS_BBOX )
	{
		IVideoDriver *driver = getIView()->getDriver();

		driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
		video::SMaterial deb_m;
		deb_m.Lighting = false;
		driver->setMaterial(deb_m);

		core::aabbox3d<f32> tbox = Box;
		getAbsoluteTransformation().transformBoxEx(tbox);

		driver->draw3DBox( tbox, video::SColor(255,255,255,255));
	}

	// draw move
	if ( 
			state == CGameObject::Move || 
			state == CGameObject::Rotation ||
			state == CGameObject::Scale
		)
		m_owner->drawFrontUpLeftVector();	
	
	if ( state == CGameObject::Rotation )
		m_owner->drawCircleAroundObject();	
#else
	if ( DebugDataVisible & scene::EDS_BBOX )
	{
		IVideoDriver *driver = getIView()->getDriver();

		driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
		video::SMaterial deb_m;
		deb_m.Lighting = false;
		driver->setMaterial(deb_m);

		core::aabbox3d<f32> tbox = Box;
		getAbsoluteTransformation().transformBoxEx(tbox);

		driver->draw3DBox( tbox, video::SColor(255,0,255,0));
	}
#endif
}
// render
// irr scenenode impl
void CGameGrassSceneNode::render()
{
	ISceneManager	*smgr = getSceneManager();
	IVideoDriver	*driver = smgr->getVideoDriver();
	

#ifdef GSEDITOR
	CGameObject::EObjectState state = m_owner->getObjectState();
	
	// draw bbox on select
	if ( 
			state == CGameObject::Move ||
			state == CGameObject::Review		
		)
		setDebugDataVisible( EDS_BBOX );
	else
		setDebugDataVisible( 0 );

	// call object draw
	m_owner->drawObject();
#endif

	// set world transform
	driver->setTransform( video::ETS_WORLD, getAbsoluteTransformation());

	// set current material with config shader
    driver->setMaterial( m_Material);

	// draw mesh with grass shader
	int meshCount = m_mesh->getMeshBufferCount();
	for ( int i = 0; i < meshCount; i++ )
		driver->drawMeshBuffer(m_mesh->getMeshBuffer(i));

	// draw bouding box
	if ( DebugDataVisible & scene::EDS_BBOX )
	{
		driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
		video::SMaterial deb_m;
		deb_m.Lighting = false;
		driver->setMaterial(deb_m);

		core::aabbox3d<f32> tbox = m_mesh->getBoundingBox();
		getAbsoluteTransformation().transformBoxEx(tbox);

		driver->draw3DBox( tbox, video::SColor(255,255,255,255));
	}

#ifdef GSEDITOR	
	// draw move
	if ( 
			state == CGameObject::Move || 
			state == CGameObject::Rotation ||
			state == CGameObject::Scale
		)
		m_owner->drawFrontUpLeftVector();	
	
	if ( state == CGameObject::Rotation )
		m_owner->drawCircleAroundObject();	
#endif

}
Exemple #15
0
void ccGBLSensor::drawMeOnly(CC_DRAW_CONTEXT& context)
{
	//we draw here a little 3d representation of the sensor
	if (MACRO_Draw3D(context))
	{
		bool pushName = MACRO_DrawEntityNames(context);

		if (pushName)
		{
			//not particulary fast
			if (MACRO_DrawFastNamesOnly(context))
				return;
			glPushName(getUniqueIDForDisplay());
		}

		//DGM FIXME: this display routine is crap!

		//apply rigid transformation
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		{
			ccIndexedTransformation sensorPos;
			if (!getAbsoluteTransformation(sensorPos,m_activeIndex))
			{
				//no visible position for this index!
				glPopMatrix();
				if (pushName)
					glPopName();
				return;
			}

			glMultMatrixf(sensorPos.data());
		}

		//test: center as sphere
		/*{
			ccSphere sphere(m_scale/10,0,"Center",12);
			sphere.showColors(true);
			sphere.setVisible(true);
			sphere.setEnabled(true);

			CC_DRAW_CONTEXT sphereContext = context;
			sphereContext.flags &= (~CC_DRAW_ENTITY_NAMES); //we must remove the 'push name flag' so that the sphere doesn't push its own!
			sphereContext._win = 0;

			sphere.setTempColor(ccColor::magenta);
			sphere.draw(sphereContext);
		}
		//*/

		const PointCoordinateType halfHeadSize = static_cast<PointCoordinateType>(0.3);

		//sensor axes
		{
			//increased width
			glPushAttrib(GL_LINE_BIT);
			GLfloat width;
			glGetFloatv(GL_LINE_WIDTH,&width);
			glLineWidth(width+1);

			PointCoordinateType axisLength = halfHeadSize * m_scale;
			ccGL::Color3v(ccColor::red.rgba);
			CCVector3 C(0,0,0);
			glBegin(GL_LINES);
			ccGL::Vertex3v(C.u);
			ccGL::Vertex3(C.x+axisLength,C.y,C.z);
			glEnd();
			ccGL::Color3v(ccColor::green.rgba);
			glBegin(GL_LINES);
			ccGL::Vertex3v(C.u);
			ccGL::Vertex3(C.x,C.y+axisLength,C.z);
			glEnd();
			ccGL::Color3v(ccColor::blue.rgba);
			glBegin(GL_LINES);
			ccGL::Vertex3v(C.u);
			ccGL::Vertex3(C.x,C.y,C.z+axisLength);
			glEnd();

			glPopAttrib();
		}

		//sensor head
		{
			CCVector3 minCorner(-halfHeadSize,-halfHeadSize,-halfHeadSize);
			CCVector3 maxCorner( halfHeadSize, halfHeadSize, halfHeadSize);
			minCorner *= m_scale;
			maxCorner *= m_scale;
			ccBBox bbHead(minCorner,maxCorner);
			bbHead.draw(m_color);
		}

		//sensor legs
		{
			CCVector3 headConnect = /*headCenter*/ - CCVector3(0,0,static_cast<PointCoordinateType>(halfHeadSize)*m_scale);
			ccGL::Color3v(m_color.rgb);
			glBegin(GL_LINES);
			ccGL::Vertex3v(headConnect.u);
			ccGL::Vertex3(-m_scale,-m_scale,-m_scale);
			ccGL::Vertex3v(headConnect.u);
			ccGL::Vertex3(-m_scale,m_scale,-m_scale);
			ccGL::Vertex3v(headConnect.u);
			ccGL::Vertex3(m_scale,0,-m_scale);
			glEnd();
		}

		if (pushName)
			glPopName();

		glPopMatrix();
	}
}