Esempio n. 1
0
shared_ptr<SceneNode> LightRenderComponent::VCreateSceneNode( void )
   {
   switch( EngineApp::GetRendererImpl() )
      {
      case Renderer::Renderer_OpenGL:
            {
            return shared_ptr<SceneNode>( ENG_NEW LightNode( m_pOwner->GetId(), this, m_pLightProps, m_pTransform ) );
            }
      default:
         ENG_ASSERT( 0 && "Unknown Renderer Implementation in GridRenderComponent" );
      }

   /*shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr( m_pOwner->GetComponent<TransformComponent>( TransformComponent::s_ComponentId ) );
   if (pTransformComponent)
   {
   WeakBaseRenderComponentPtr weakThis(this);

   switch ( EngineApp::GetRendererImpl() )
   {
   case Renderer::Renderer_OpenGL :
   {
   return shared_ptr<SceneNode>( ENG_NEW LightNode( m_pOwner->GetId(), weakThis, m_pLightProps, pTransformComponent->GetTransform( ) ) );
   }
   default:
   ENG_ASSERT( 0 && "Unknown Renderer Implementation in GridRenderComponent" );
   }
   }*/
    return shared_ptr<SceneNode>();
   }
Esempio n. 2
0
UInt32 SceneTreeModel::getChildCount(const boost::any& parent) const
{
    if(parent.type() == typeid(Scene* const))
    {
        return SceneComponentsLast;
    }
    else if(parent.type() == typeid(UInt32))
    {
        UInt32 Value(boost::any_cast<UInt32>(parent));
        switch(Value)
        {
        case BasicComponent:              //Basic
        case BackgroundComponent:              //Background
        case CameraComponent:              //Camera
            return 0;
            break;
        case ForegroundsComponent:              //Foregrounds
            return getInternalRoot()->getPrimaryViewport()->getMFForegrounds()->size();
            break;
        case SceneObjectsComponent:              //Models
            return getInternalRoot()->getMFSceneObjects()->size();
            break;
        case LightsComponent:              //Lights
            {
                NodeRecPtr LightNode(getInternalRoot()->getPrimaryViewport()->getRoot());
                UInt32 NumLights(0);

                while(LightNode->getNChildren() > 0 &&
                      LightNode->getChild(0)->getCore()->getType().isDerivedFrom(Light::getClassType()))
                {
                    LightNode = LightNode->getChild(0);

                    ++NumLights;
                }
                return NumLights;
            }
            break;
        case DynamicsComponent:              //Dynamics
            return DynamicsComponentsLast - DynamicsComponentsFirst;
            break;
        case ScriptsComponent:              //Scripts
            return 0;
            break;
        case BehavioursComponent:              //Behaviours
            return 0;
            break;
        case AnimationsComponent:              //Animations
            return 0;
            break;
        }
    }
    else
    {
        return 0;
    }
}
//----------------------------------------------------------------------------
void ReflectionsAndShadows::CreatePlanarReflection ()
{
    Light* projector = new0 Light(Light::LT_DIRECTIONAL);
    projector->DVector = -AVector::UNIT_X;
    LightNode* projectorNode = new0 LightNode(projector);
    mScene->AttachChild(projectorNode);

    mPREffect = new0 PlanarReflectionEffect(1);
    mPREffect->SetPlane(0, mPlane1);
    mPREffect->SetReflectance(0, 0.25f);
}
//----------------------------------------------------------------------------
void ReflectionsAndShadows::CreatePlanarShadow ()
{
    Light* projector = new0 Light(Light::LT_POINT);
    projector->Position = APoint(30.0f, -50.0f, 80.0f);
    LightNode* projectorNode = new0 LightNode(projector);
    mScene->AttachChild(projectorNode);

    mPSEffect = new0 PlanarShadowEffect(1, mBiped);
    Float4 shadowColor(0.0f, 0.0f, 0.0f, 0.5f);
    mPSEffect->SetPlane(0, mPlane0);
    mPSEffect->SetProjector(0, projector);
    mPSEffect->SetShadowColor(0, shadowColor);
}
Esempio n. 5
0
//----------------------------------------------------------------------------
void PlanarShadows::CreatePlanarShadow ()
{
#if 1
	Light* projector = new0 Light(Light::LT_POINT);
	projector->Position = APoint(152.0f, -55.0f, 53.0f);
#else
	Light* projector = new0 Light(Light::LT_DIRECTIONAL);
	projector->DVector = AVector(0.25f, 0.25f, -1.0f);
	projector->DVector.Normalize();
#endif
	mProjectorNode = new0 LightNode(projector);
	mScene->AttachChild(mProjectorNode);

	mPSEffect = new0 PlanarShadowEffect(2, mBiped);
	Float4 shadowColor(0.0f, 0.0f, 0.0f, 0.5f);
	mPSEffect->SetPlane(0, mPlane0);
	mPSEffect->SetProjector(0, projector);
	mPSEffect->SetShadowColor(0, shadowColor);
	mPSEffect->SetPlane(1, mPlane1);
	mPSEffect->SetProjector(1, projector);
	mPSEffect->SetShadowColor(1, shadowColor);
}
Esempio n. 6
0
//----------------------------------------------------------------------------
void Castle::CreateLights ()
{
    mDLight = new0 Light(Light::LT_DIRECTIONAL);
    mDLight->Ambient = Float4(1.0f, 1.0f, 1.0f, 1.0f);
    mDLight->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
    mDLight->Specular = Float4(1.0f, 1.0f, 1.0f, 1.0f);

    LightNode* lightNode = new0 LightNode(mDLight);
    lightNode->LocalTransform.SetTranslate(APoint(1628.448730f, -51.877197f,
        0.0f));
    lightNode->LocalTransform.SetRotate(HMatrix(AVector(-1.0f, 0.0f, 0.0f),
        Mathf::HALF_PI));

    mDLightRoot = new0 Node();
    mDLightRoot->LocalTransform.SetTranslate(APoint(-1824.998657f,
        -1531.269775f, 3886.592773f));
    mDLightRoot->LocalTransform.SetRotate(HMatrix(AVector(-0.494124f,
        0.325880f, 0.806005f), 1.371538f));

    mDLightRoot->AttachChild(lightNode);
    mDLightRoot->Update();
}
Esempio n. 7
0
bool ZoneMap::load(std::string p_zoneName)
{
	std::cout << "Loading map map\\zones\\" << p_zoneName << "... ";

	std::ifstream _file;
	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Info.cfg").c_str(), std::ios::binary);
	{
		if(!_file.good())
		{
			std::cout << "No Info.cfg file found." << std::endl;
			return false;
		}
	}
	_file.close();
	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Ground.tmf").c_str(), std::ios::binary);
	{
		if(!_file.good())
		{
			std::cout << "No Ground.tmf file found." << std::endl;
			return false;
		}
	}
	_file.close();
	_file.open(std::string("map\\zones\\" + p_zoneName + "\\World.tmf").c_str(), std::ios::binary);
	{
		if(!_file.good())
		{
			std::cout << "No World.tmf file found." << std::endl;
			return false;
		}
	}
	_file.close();
	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Entity.tmf").c_str(), std::ios::binary);
	{
		if(!_file.good())
		{
			std::cout << "No Entity.tmf file found." << std::endl;
			return false;
		}
	}
	_file.close();
	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Sky.tmf").c_str(), std::ios::binary);
	{
		if(!_file.good())
		{
			std::cout << "No Sky.tmf file found." << std::endl;
			return false;
		}
	}
	_file.close();



	clear();

	m_mapName = p_zoneName;

	Uint32 _length, _index;
	char* _data;
	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Info.cfg").c_str(), std::ios::binary);
	{
		_index = 0;

		_file.seekg(0, _file.end);
		_length = Uint32(_file.tellg());
		_file.seekg(0, _file.beg);
		_data = new char[_length];
		_file.read(_data, _length);

		m_mapSize.x = FileExt::readShort(_data, _index);
		m_mapSize.y = FileExt::readShort(_data, _index);

		init();
		delete[] _data;
	}
	_file.close();

	Uint16 _tileCount;
	Uint16 _tileId, _mapIndex;

	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Ground.tmf").c_str(), std::ios::binary);
	{
		_mapIndex = 0;
		_index = 0;

		_file.seekg(0, _file.end);
		_length = Uint32(_file.tellg());
		_file.seekg(0, _file.beg);
		_data = new char[_length];
		_file.read(_data, _length);

		while(_mapIndex < m_mapSize.x * m_mapSize.y && _index < _length)
		{
			_tileCount = FileExt::readShort(_data, _index);
			_tileId = FileExt::readShort(_data, _index);

			for(Uint16 i = 0; i < _tileCount; i++)
			{
				m_tileData[0][_mapIndex % m_mapSize.x][int(floor(GLfloat(_mapIndex) / m_mapSize.x))] = _tileId;
				_mapIndex++;
			}
		}
		delete[] _data;
	}
	_file.close();

	_file.open(std::string("map\\zones\\" + p_zoneName + "\\World.tmf").c_str(), std::ios::binary);
	{
		_mapIndex = 0;
		_index = 0;

		_file.seekg(0, _file.end);
		_length = Uint32(_file.tellg());
		_file.seekg(0, _file.beg);
		_data = new char[_length];
		_file.read(_data, _length);


		Uint16 _objCount = FileExt::readShort(_data, _index);
		Uint16 _objNameLen = 0;
		std::string _objName;
		Uint16 _interactionType, _tileTex;

		m_worldObjects.clear();

		for(Uint16 i = 0; i < _objCount; i++)
		{
			_objName = "";
			_objNameLen = FileExt::readChar(_data, _index);
			for(Uint16 j = 0; j < Uint16(_objNameLen); j++)
				_objName = _objName + char(FileExt::readChar(_data, _index));
			_interactionType = FileExt::readShort(_data, _index);
			_tileTex = FileExt::readShort(_data, _index);
			m_worldObjects.push_back(WorldObject(_objName, _interactionType, _tileTex));
			switch(m_worldObjects[i].m_interactionType)
			{
			case 0: // NONE

				break;
			case 1: // SOLID

				break;
			case 2: // SWITCH
				m_worldObjects[i].m_frequency = FileExt::readChar(_data, _index);
				break;
			case 3: // SOLID SWITCH
				m_worldObjects[i].m_frequency = FileExt::readChar(_data, _index);
				break;
			case 4: // PORTAL
				m_worldObjects[i].m_frequency = FileExt::readChar(_data, _index);
				_objName = "";
				_objNameLen = FileExt::readChar(_data, _index);
				for(Uint16 j = 0; j < Uint16(_objNameLen); j++)
					_objName = _objName + char(FileExt::readChar(_data, _index));
				m_worldObjects[i].m_portalDest = _objName;
				m_worldObjects[i].m_destX = FileExt::readShort(_data, _index);
				m_worldObjects[i].m_destY = FileExt::readShort(_data, _index);
				break;
			case 5: // DIRECTION
				m_worldObjects[i].m_direction = FileExt::readChar(_data, _index);
				break;
			case 6: // LIGHT
				m_worldObjects[i].m_lightValue = FileExt::readChar(_data, _index);
				break;
			}
		}


		while(_mapIndex < m_mapSize.x * m_mapSize.y && _index < _length)
		{
			_tileCount = FileExt::readShort(_data, _index);
			_tileId = FileExt::readShort(_data, _index);

			for(Uint16 i = 0; i < _tileCount; i++)
			{
				m_tileData[1][_mapIndex % m_mapSize.x][int(floor(GLfloat(_mapIndex) / m_mapSize.x))] = _tileId;
				if(m_worldObjects[_tileId].m_interactionType == 6)
					addLight(LightNode(_mapIndex % m_mapSize.x, floor(GLfloat(_mapIndex) / m_mapSize.x), m_worldObjects[_tileId].m_lightValue));
				_mapIndex++;
			}
		}
		delete[] _data;
	}
	_file.close();

	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Sky.tmf").c_str(), std::ios::binary);
	{
		_mapIndex = 0;
		_index = 0;

		_file.seekg(0, _file.end);
		_length = Uint32(_file.tellg());
		_file.seekg(0, _file.beg);
		_data = new char[_length];
		_file.read(_data, _length);

		while(_mapIndex < m_mapSize.x * m_mapSize.y && _index < _length)
		{
			_tileCount = FileExt::readShort(_data, _index);
			_tileId = FileExt::readShort(_data, _index);

			for(Uint16 i = 0; i < _tileCount; i++)
			{
				m_tileData[2][_mapIndex % m_mapSize.x][int(floor(GLfloat(_mapIndex) / m_mapSize.x))] = _tileId;
				_mapIndex++;
			}
		}
		delete[] _data;
	}
	_file.close();

	_file.open(std::string("map\\zones\\" + p_zoneName + "\\Entity.tmf").c_str(), std::ios::binary);
	{
		_mapIndex = 0;
		_index = 0;

		_file.seekg(0, _file.end);
		_length = Uint32(_file.tellg());
		_file.seekg(0, _file.beg);
		_data = new char[_length];
		_file.read(_data, _length);


		Uint16 _objCount = FileExt::readShort(_data, _index);
		Uint16 _objNameLen = 0;
		std::string _objName;
		Uint16 _texNameLen = 0;
		std::string _texName;

		m_entities.clear();

		for(Uint16 i = 0; i < _objCount; i++)
		{
			_objName = "";
			_objNameLen = FileExt::readShort(_data, _index);
			for(Uint16 j = 0; j < Uint16(_objNameLen); j++)
				_objName = _objName + char(FileExt::readChar(_data, _index));
			m_entities.push_back(Entity(_objName));
			m_entities[i].m_pos.x = FileExt::readShort(_data, _index);
			m_entities[i].m_pos.y = FileExt::readShort(_data, _index);
		}
		delete[] _data;
	}
	_file.close();

	Uint16 _texNameLen = 0;
	std::string _texName = "";
	for(Uint16 i = 0; i < m_entities.size(); i++)
	{
		_file.open(std::string("map\\zones\\" + p_zoneName + "\\entities\\" + m_entities[i].m_name + "\\Info.cfg").c_str(), std::ios::binary);
		{
			if(!_file.good())
				continue;
			_index = 0;
			_file.seekg(0, _file.end);
			_length = Uint32(_file.tellg());
			_file.seekg(0, _file.beg);
			_data = new char[_length];
			_file.read(_data, _length);
			m_entities[i].m_entityType = FileExt::readChar(_data, _index);
			_texNameLen = FileExt::readShort(_data, _index);
			_texName = "";
			for(Uint16 i = 0; i < _texNameLen; i++)
				_texName += FileExt::readChar(_data, _index);
			m_entities[i].m_entityTex = LTexture::getInstance().getImage(_texName);
			m_entities[i].m_entityTex.setName(_texName);
			m_entities[i].m_entityTexId = FileExt::readShort(_data, _index);
			delete[] _data;
		}
		_file.close();
	}

	for(Uint16 i = 1; i < m_entities.size(); i++)
	{
		_file.open(std::string("map\\zones\\" + p_zoneName + "\\entities\\" + m_entities[i].m_name + "\\Interact").c_str(), std::ios::binary);
		{
			if(!_file.good())
				continue;
			_index = 0;
			_file.seekg(0, _file.end);
			_length = Uint32(_file.tellg());
			_file.seekg(0, _file.beg);
			_data = new char[_length];
			_file.read(_data, _length);
			for(Uint16 j = 0; j < _length; j++)
				m_entities[i].m_interact += FileExt::readChar(_data, _index);
			delete[] _data;
		}
		_file.close();
	}

	for(Uint16 i = 1; i < m_entities.size(); i++)
	{
		_file.open(std::string("map\\zones\\" + p_zoneName + "\\entities\\" + m_entities[i].m_name + "\\Idle").c_str(), std::ios::binary);
		{
			if(!_file.good())
				continue;
			_index = 0;
			_file.seekg(0, _file.end);
			_length = Uint32(_file.tellg());
			_file.seekg(0, _file.beg);
			_data = new char[_length];
			_file.read(_data, _length);
			for(Uint16 j = 0; j < _length; j++)
				m_entities[i].m_idle += FileExt::readChar(_data, _index);
			delete[] _data;
		}
		_file.close();
	}

	std::cout << "Complete." << std::endl;

	return true;
}
Esempio n. 8
0
/***************************************************************************\
 *                           Instance methods                              *
\***************************************************************************/
boost::any SceneTreeModel::getChild(const boost::any& parent, const UInt32& index) const
{
    if(parent.type() == typeid(Scene* const))
    {
        switch(index)
        {
        case BasicComponent:              //Basic
            return boost::any(UInt32(BasicComponent));
            break;
        case ForegroundsComponent:              //Foregrounds
            return boost::any(UInt32(ForegroundsComponent));
            break;
        case BackgroundComponent:              //Background
            return boost::any(UInt32(BackgroundComponent));
            break;
        case CameraComponent:              //Camera
            return boost::any(UInt32(CameraComponent));
            break;
        case SceneObjectsComponent:              //Models
            return boost::any(UInt32(SceneObjectsComponent));
            break;
        case LightsComponent:              //Models
            return boost::any(UInt32(LightsComponent));
            break;
        case DynamicsComponent:              //Dynamics
            return boost::any(UInt32(DynamicsComponent));
            break;
        }
    }
    else if(parent.type() == typeid(UInt32))
    {
        UInt32 Value(boost::any_cast<UInt32>(parent));
        switch(Value)
        {
        case BasicComponent:              //Basic
        case BackgroundComponent:              //Background
        case CameraComponent:              //Camera
            return boost::any();
            break;
        case ForegroundsComponent:              //Foregrounds
            if(index < getInternalRoot()->getPrimaryViewport()->getMFForegrounds()->size())
            {
                return boost::any(getInternalRoot()->getPrimaryViewport()->getForegrounds(index));
            }
            break;
        case SceneObjectsComponent:              //Models
            if(index < getInternalRoot()->getMFSceneObjects()->size())
            {
                return boost::any(getInternalRoot()->getSceneObjects(index));
            }
            break;
        case LightsComponent:              //Lights
            {
                NodeRecPtr LightNode(getInternalRoot()->getPrimaryViewport()->getRoot());

                for(UInt32 i(0) ; i<=index ; ++i)
                {
                    if(LightNode->getNChildren() > 0 &&
                        LightNode->getChild(0)->getCore()->getType().isDerivedFrom(Light::getClassType()))
                    {
                        LightNode = LightNode->getChild(0);
                    }
                }

                if(LightNode != NULL)
                {
                    return boost::any(dynamic_cast<Light*>(LightNode->getCore()));
                }
                else
                {
                    return boost::any();
                }
            }
            break;
        case DynamicsComponent:              //Dynamics
            switch(index+DynamicsComponentsFirst)
            {
            case ScriptsComponent:              //Scripts
                return boost::any(UInt32(ScriptsComponent));
                break;
            case BehavioursComponent:              //Behaviours
                return boost::any(UInt32(BehavioursComponent));
                break;
            case AnimationsComponent:              //Animations
                return boost::any(UInt32(AnimationsComponent));
                break;
            }
            break;
        }
    }
    return boost::any();
}
Esempio n. 9
0
UInt32 SceneTreeModel::getIndexOfChild(const boost::any& parent, const boost::any& child) const
{
    if(parent.type() == typeid(Scene* const))
    {
        UInt32 Value(boost::any_cast<UInt32>(child));
        switch(Value)
        {
        case BasicComponent:              //Basic
            return BasicComponent;
            break;
        case ForegroundsComponent:              //Foregrounds
            return ForegroundsComponent;
            break;
        case BackgroundComponent:              //Background
            return BackgroundComponent;
            break;
        case CameraComponent:              //Camera
            return CameraComponent;
            break;
        case SceneObjectsComponent:              //Models
            return SceneObjectsComponent;
            break;
        case DynamicsComponent:              //Dynamics
            return DynamicsComponent;
            break;
        }
    }
    else if(parent.type() == typeid(UInt32))
    {
        UInt32 Value(boost::any_cast<UInt32>(parent));
        switch(Value)
        {
        case BasicComponent:              //Basic
        case BackgroundComponent:              //Background
        case CameraComponent:              //Camera
            return 0;
            break;
        case ForegroundsComponent:              //Foregrounds
            for(UInt32 i(0) ; i<getInternalRoot()->getPrimaryViewport()->getMFForegrounds()->size() ; ++i)
            {
                if(getInternalRoot()->getPrimaryViewport()->getForegrounds(i) == boost::any_cast<Foreground* const>(child))
                {
                    return i;
                }
            }
            return 0;
            break;
        case SceneObjectsComponent:              //Models
            for(UInt32 i(0) ; i<getInternalRoot()->getMFSceneObjects()->size() ; ++i)
            {
                if(getInternalRoot()->getSceneObjects(i) == boost::any_cast<SceneObject* const>(child))
                {
                    return i;
                }
            }
            break;
        case LightsComponent:              //Lights
            {
                UInt32 NumLights(getChildCount(parent));
                UInt32 FoundLights(0);

                NodeRecPtr LightNode(getInternalRoot()->getPrimaryViewport()->getRoot());
                while(FoundLights < NumLights &&
                      LightNode->getNChildren() > 0 &&
                      LightNode->getChild(0)->getCore()->getType().isDerivedFrom(Light::getClassType()))
                {
                    LightNode = LightNode->getChild(0);

                    if(LightNode ==boost::any_cast<Light* const>(child)->getParents().front() )
                    {
                        return FoundLights;
                    }

                    ++FoundLights;
                }
            }
            break;
        case DynamicsComponent:              //Dynamics
            UInt32 Value(boost::any_cast<UInt32>(child));
            switch(Value)
            {
                case ScriptsComponent:              //Scripts
                    return ScriptsComponent - DynamicsComponentsFirst;
                    break;
                case BehavioursComponent:              //Behaviours
                    return BehavioursComponent - DynamicsComponentsFirst;
                    break;
                case AnimationsComponent:              //Animations
                    return AnimationsComponent - DynamicsComponentsFirst;
                    break;
            }
        }
    }
    else
    {
        return 0;
    }
}