Entity* SkyboxSystem::AddSkybox()
	{
		Entity* result = skyboxEntity;
		
		if(NULL == skyboxEntity)
		{
			SkyboxRenderObject* skyboxRenderObject = new SkyboxRenderObject();
			
			AABBox3 box = AABBox3(Vector3(-0.5f, -0.5f, -0.5f), Vector3(0.5f, 0.5f, 0.5f));
			skyboxRenderObject->Initialize(box); //first time initialization
			
			RenderComponent* renderComponent = new RenderComponent();
			renderComponent->SetRenderObject(skyboxRenderObject);
			
			
			result = new Entity();
			result->SetName("Skybox");

			result->RemoveComponent(Component::RENDER_COMPONENT);
			result->AddComponent(renderComponent);
			renderComponent->Release();

			GetScene()->AddNode(result);
			
			Matrix4 * worldTransformPointer = ((TransformComponent*)result->GetComponent(Component::TRANSFORM_COMPONENT))->GetWorldTransformPtr();
			skyboxRenderObject->SetWorldTransformPtr(worldTransformPointer);
			result->GetScene()->renderSystem->MarkForUpdate(skyboxRenderObject);
			SafeRelease(skyboxRenderObject);
			
			DVASSERT(skyboxEntity);
			result->Release();
		}
		
		return result;
	}
Beispiel #2
0
ParticleEmitter::ParticleEmitter()
{
    type = TYPE_PARTICLE_EMTITTER;
    Cleanup(false);

    bbox = AABBox3(Vector3(), Vector3());
}
void RenderObject::RecalcBoundingBox()
{
    bbox = AABBox3();

    uint32 size = (uint32)renderBatchArray.size();
    for (uint32 k = 0; k < size; ++k)
    {
        bbox.AddAABBox(renderBatchArray[k]->GetBoundingBox());
    }
}
void PolygonGroup::ApplyMatrix(const Matrix4 & matrix)
{
    aabbox = AABBox3(); // reset bbox
    
    Matrix4 normalMatrix4;
    matrix.GetInverse(normalMatrix4);
    normalMatrix4.Transpose();
    Matrix3 normalMatrix3;
    normalMatrix3 = normalMatrix4;

    for (int32 vi = 0; vi < vertexCount; ++vi)
    {
        Vector3 vertex;
        GetCoord(vi, vertex);
        vertex = vertex * matrix;
        SetCoord(vi, vertex);
        
        Vector3 normal;
        GetNormal(vi, normal);
        normal = normal * normalMatrix3;
        SetNormal(vi, normal);
    }    
}
void ParticleLayer3D::PrepareRenderData(Camera* camera)
{
	AABBox3 bbox;
	if (emitter->GetWorldTransformPtr())
	{
		Vector3 emmiterPos = emitter->GetWorldTransformPtr()->GetTranslationVector();
		bbox = AABBox3(emmiterPos, emmiterPos);
	}	

	// Yuri Coder, 2013/06/07. Don't draw SuperEmitter layers - see pls DF-1251 for details.
	if (!sprite || type == TYPE_SUPEREMITTER_PARTICLES)
	{		
		//build bounding box as sum of inner particle emitters bboxes
		if (type == TYPE_SUPEREMITTER_PARTICLES)
		{
			Particle *current = head;
			while (current)
			{
				bbox.AddAABBox(current->GetInnerEmitter()->GetBoundingBox());
				current=current->next;
			}
		}
		
		renderBatch->SetLayerBoundingBox(bbox);
		renderBatch->SetTotalCount(0);		
		return;
	}


	Matrix4 mv;
	Matrix3 rotation;
	bool worldAlign = particleOrientation&ParticleLayer::PARTICLE_ORIENTATION_WORLD_ALIGN;
	if (!worldAlign)
	{
		rotation = emitter->GetRotationMatrix();
	}
	Vector<std::pair<Vector3, Vector3> > basises;
	if (particleOrientation&ParticleLayer::PARTICLE_ORIENTATION_CAMERA_FACING)
	{
		mv = camera->GetMatrix();
		basises.push_back(std::pair<Vector3, Vector3>(Vector3(mv._01, mv._11, mv._21), Vector3(mv._00, mv._10, mv._20)));
	}
	if (particleOrientation&ParticleLayer::PARTICLE_ORIENTATION_X_FACING)
	{
		Vector3 up(0,1,0);
		Vector3 left(0,0,1);
		if (!worldAlign)
		{
			up = up*rotation;
			up.Normalize();
			left = left*rotation;
			left.Normalize();
		}
		basises.push_back(std::pair<Vector3, Vector3>(up, left));
	}
	if (particleOrientation&ParticleLayer::PARTICLE_ORIENTATION_Y_FACING)
	{
		Vector3 up(0,0,1);
		Vector3 left(1,0,0);
		if (!worldAlign)
		{
			up = up*rotation;
			up.Normalize();
			left = left*rotation;
			left.Normalize();
		}
		basises.push_back(std::pair<Vector3, Vector3>(up, left));
	}
	if (particleOrientation&ParticleLayer::PARTICLE_ORIENTATION_Z_FACING)
	{
		Vector3 up(0,1,0);
		Vector3 left(1,0,0);
		if (!worldAlign)
		{
			up = up*rotation;
			up.Normalize();
			left = left*rotation;
			left.Normalize();
		}
		basises.push_back(std::pair<Vector3, Vector3>(up, left));
	}
	
	int32 planesCount =  basises.size();

	direction = camera->GetDirection();

	verts.clear();
	textures.clear();
	colors.clear();

	if (enableFrameBlend)
	{
		textures2.clear();
		times.clear();
	}
	int32 totalCount = 0;

	// Reserve the memory for vectors to avoid the resize operations. Actually there can be less than count
	// particles (for Single Particle or Superemitter one), but never more than count.
	static const int32 POINTS_PER_PARTICLE = 4;
	static const int32 INDICES_PER_PARTICLE = 6;
	verts.resize(count * POINTS_PER_PARTICLE * 3 * planesCount); // 4 vertices per each particle, 3 coords per vertex.
	textures.resize(count * POINTS_PER_PARTICLE * 2 * planesCount); // 4 texture coords per particle, 2 values per texture coord.
	colors.resize(count * POINTS_PER_PARTICLE*planesCount);	
	
	//frame blending
	if (enableFrameBlend)
	{
		textures2.resize(count * POINTS_PER_PARTICLE * 2 * planesCount);
		times.resize(count * POINTS_PER_PARTICLE * planesCount); //single time value per vertex
	}

	Particle * current = head;
	if(current)
	{
		renderBatch->GetMaterial()->GetRenderState()->SetTexture(sprite->GetTexture(current->frame));
	}

	int32 verticesCount = 0;
	int32 texturesCount = 0;
	int32 texturesCount2 = 0;
	int32 timesCount = 0;
	int32 colorsCount = 0;	
	while(current != 0)
	{		
		for (int32 i=0; i<planesCount; ++i)
		{		
			_up = basises[i].first;
			_left = basises[i].second;
			Vector3 topRight;
			Vector3 topLeft;
			Vector3 botRight;
			Vector3 botLeft;

			if (IsLong())
			{
				CalcLong(current, topLeft, topRight, botLeft, botRight);
			}
			else
			{
				CalcNonLong(current, topLeft, topRight, botLeft, botRight);
			}

			verts[verticesCount] = topLeft.x;//0
			verticesCount ++;
			verts[verticesCount] = topLeft.y;
			verticesCount ++;
			verts[verticesCount] = topLeft.z;
			verticesCount ++;

			verts[verticesCount] = topRight.x;//1
			verticesCount ++;
			verts[verticesCount] = topRight.y;
			verticesCount ++;
			verts[verticesCount] = topRight.z;
			verticesCount ++;

			verts[verticesCount] = botLeft.x;//2
			verticesCount ++;
			verts[verticesCount] = botLeft.y;
			verticesCount ++;
			verts[verticesCount] = botLeft.z;
			verticesCount ++;

			verts[verticesCount] = botRight.x;//3
			verticesCount ++;
			verts[verticesCount] = botRight.y;
			verticesCount ++;
			verts[verticesCount] = botRight.z;
			verticesCount ++;

			bbox.AddPoint(topLeft);
			bbox.AddPoint(topRight);
			bbox.AddPoint(botLeft);
			bbox.AddPoint(botRight);

			float32 *pT = sprite->GetTextureVerts(current->frame);

			textures[texturesCount] = pT[0];
			texturesCount ++;
			textures[texturesCount] = pT[1];
			texturesCount ++;

			textures[texturesCount] = pT[2];
			texturesCount ++;
			textures[texturesCount] = pT[3];
			texturesCount ++;

			textures[texturesCount] = pT[4];
			texturesCount ++;
			textures[texturesCount] = pT[5];
			texturesCount ++;

			textures[texturesCount] = pT[6];
			texturesCount ++;
			textures[texturesCount] = pT[7];
			texturesCount ++;

			//frame blending
			if (enableFrameBlend)
			{
				int32 nextFrame = current->frame+1;
				if (nextFrame >= sprite->GetFrameCount())
				{
					if (loopSpriteAnimation)
						nextFrame = 0;
					else
						nextFrame = sprite->GetFrameCount()-1;
					
				}
				pT = sprite->GetTextureVerts(nextFrame);
				textures2[texturesCount2] = pT[0];
				texturesCount2 ++;
				textures2[texturesCount2] = pT[1];
				texturesCount2 ++;

				textures2[texturesCount2] = pT[2];
				texturesCount2 ++;
				textures2[texturesCount2] = pT[3];
				texturesCount2 ++;

				textures2[texturesCount2] = pT[4];
				texturesCount2 ++;
				textures2[texturesCount2] = pT[5];
				texturesCount2 ++;

				textures2[texturesCount2] = pT[6];
				texturesCount2 ++;
				textures2[texturesCount2] = pT[7];
				texturesCount2 ++;
				

				times[timesCount] = current->animTime;
				timesCount++;
				times[timesCount] = current->animTime;
				timesCount++;
				times[timesCount] = current->animTime;
				timesCount++;
				times[timesCount] = current->animTime;
				timesCount++;
			}
			

			// Yuri Coder, 2013/04/03. Need to use drawColor here instead of just colot
			// to take colorOverlife property into account.
			uint32 color = (((uint32)(current->drawColor.a*255.f))<<24) |  (((uint32)(current->drawColor.b*255.f))<<16) |
				(((uint32)(current->drawColor.g*255.f))<<8) | ((uint32)(current->drawColor.r*255.f));
			for(int32 i = 0; i < POINTS_PER_PARTICLE; ++i)
			{
				colors[i + colorsCount] = color;
			}
			colorsCount += POINTS_PER_PARTICLE;

			totalCount++;
		}
		current = TYPE_PARTICLES == type ? current->next : 0;
	}	
	int indexCount = indices.size()/INDICES_PER_PARTICLE;
	if (totalCount>indexCount)
	{
		indices.resize(totalCount*INDICES_PER_PARTICLE);
		for (;indexCount<totalCount; ++indexCount)
		{
			indices[indexCount*INDICES_PER_PARTICLE+0] = indexCount*POINTS_PER_PARTICLE+0;
			indices[indexCount*INDICES_PER_PARTICLE+1] = indexCount*POINTS_PER_PARTICLE+1;
			indices[indexCount*INDICES_PER_PARTICLE+2] = indexCount*POINTS_PER_PARTICLE+2;
			indices[indexCount*INDICES_PER_PARTICLE+3] = indexCount*POINTS_PER_PARTICLE+2;
			indices[indexCount*INDICES_PER_PARTICLE+4] = indexCount*POINTS_PER_PARTICLE+1;
			indices[indexCount*INDICES_PER_PARTICLE+5] = indexCount*POINTS_PER_PARTICLE+3; //preserve order
		}
	}

	renderBatch->SetTotalCount(totalCount);	
	renderBatch->SetLayerBoundingBox(bbox);
	if(totalCount > 0)
	{					
		renderData->SetStream(EVF_VERTEX, TYPE_FLOAT, 3, 0, &verts.front());
		renderData->SetStream(EVF_TEXCOORD0, TYPE_FLOAT, 2, 0, &textures.front());
		renderData->SetStream(EVF_COLOR, TYPE_UNSIGNED_BYTE, 4, 0, &colors.front());				
		if (enableFrameBlend)
		{
			renderData->SetStream(EVF_TEXCOORD1, TYPE_FLOAT, 2, 0, &textures2.front());
			renderData->SetStream(EVF_TIME, TYPE_FLOAT, 1, 0, &times.front());
		}				
	}
	
}
bool SwitchToRenerObjectConverter::MergeSwitch(Entity * entity)
{
    Vector<Entity*> entitiesToRemove;

    SwitchComponent * sw = GetSwitchComponent(entity);
    if(sw)
    {
        RenderComponent * rc = GetRenderComponent(entity);
        RenderObject * ro = 0;
        if(!rc)
        {
            ro = new Mesh();
            rc = new RenderComponent(ro);
            ro->Release();

            ro->SetAABBox(AABBox3(Vector3(0, 0, 0), Vector3(0, 0, 0)));
            entity->AddComponent(rc);
        }
        else
        {
            ro = rc->GetRenderObject();
        }

        DVASSERT(ro);

        int32 size = entity->GetChildrenCount();
        for(int32 i = 0; i < size; ++i)
        {
            Entity * sourceEntity = entity->GetChild(i);
            RenderObject * sourceRenderObject = GetRenderObject(sourceEntity);

            //workaround for custom properties for crashed model
            if(1 == i) // crash model
            {
                KeyedArchive *childProps = GetCustomPropertiesArchieve(sourceEntity);
                if(childProps && childProps->IsKeyExists("CollisionType"))
                {
                    KeyedArchive *entityProps = GetOrCreateCustomProperties(entity)->GetArchive();
                    entityProps->SetInt32("CollisionTypeCrashed", childProps->GetInt32("CollisionType", 0));
                }
            }
            //end of custom properties

            Vector<std::pair<Entity*, RenderObject*> > renderPairs;
            if(sourceRenderObject)
            {
                renderPairs.push_back(std::make_pair(sourceEntity, sourceRenderObject));
            }
            else
            {
                FindRenderObjectsRecursive(sourceEntity, renderPairs);
                DVASSERT(renderPairs.size() == 1);
                sourceRenderObject = renderPairs[0].second;
            }

            if(sourceRenderObject)
            {
                TransformComponent * sourceTransform = GetTransformComponent(sourceEntity);
                if (sourceTransform->GetLocalTransform() != Matrix4::IDENTITY)
                {
                    PolygonGroup * pg = sourceRenderObject->GetRenderBatchCount() > 0 ? sourceRenderObject->GetRenderBatch(0)->GetPolygonGroup() : 0;
                    if(pg && bakedPolygonGroups.end() == bakedPolygonGroups.find(pg))
                    {
                        sourceRenderObject->BakeGeometry(sourceTransform->GetLocalTransform());
                        bakedPolygonGroups.insert(pg);
                    }
                }

                uint32 sourceSize = sourceRenderObject->GetRenderBatchCount();
                while(sourceSize)
                {
                    int32 lodIndex, switchIndex;
                    RenderBatch * sourceRenderBatch = sourceRenderObject->GetRenderBatch(0, lodIndex, switchIndex);
                    sourceRenderBatch->Retain();
                    sourceRenderObject->RemoveRenderBatch(sourceRenderBatch);
                    ro->AddRenderBatch(sourceRenderBatch, lodIndex, i);
                    sourceRenderBatch->Release();
                    sourceSize--;
                }
            }

            renderPairs[0].first->RemoveComponent(Component::RENDER_COMPONENT);

            LodComponent * lc = GetLodComponent(sourceEntity);
            if((0 != lc) && (0 == GetLodComponent(entity)))
            {
                LodComponent * newLod = (LodComponent*)lc->Clone(entity);
                entity->AddComponent(newLod);
            }

            renderPairs[0].first->RemoveComponent(Component::LOD_COMPONENT);

            if(sourceEntity->GetChildrenCount() == 0)
            {
                entitiesToRemove.push_back(sourceEntity);
            }
        }
    }

    uint32 entitiesToRemoveCount = entitiesToRemove.size();
    for(uint32 i = 0; i < entitiesToRemoveCount; ++i)
    {
        entitiesToRemove[i]->GetParent()->RemoveNode(entitiesToRemove[i]);
    }

    return false;
}
Beispiel #7
0
void QuadTree::BuildRecursive(QuadTreeNode * node, List<MeshInstanceNode*> & meshNodes)
{
    cache.Reset();
    
    //meshNodes
    AABBox3 bbox = node->GetBoundingBox();
    
    AABBox3 childBoxes[4]; 
    Vector3 halfSize = (bbox.max - bbox.min) / 2.0f;
    childBoxes[0] = AABBox3(Vector3(bbox.min.x, bbox.min.y, bbox.min.z), Vector3(bbox.min.x + halfSize.x, bbox.min.y + halfSize.y, bbox.max.z));
    childBoxes[1] = AABBox3(Vector3(bbox.min.x + halfSize.x, bbox.min.y, bbox.min.z), Vector3(bbox.max.x, bbox.min.y + halfSize.y, bbox.max.z));
    childBoxes[2] = AABBox3(Vector3(bbox.min.x, bbox.min.y + halfSize.y, bbox.min.z), Vector3(bbox.min.x + halfSize.x, bbox.max.y, bbox.max.z));
    childBoxes[3] = AABBox3(Vector3(bbox.min.x + halfSize.x, bbox.min.y + halfSize.y, bbox.min.z), Vector3(bbox.max.x, bbox.max.y, bbox.max.z));
    
    AABBox3 realChildBox[4];
    
    int32 childCount[4] = {0, 0, 0, 0};
    List<MeshInstanceNode*> childLists[4];
    
    for (List<MeshInstanceNode*>::iterator it = meshNodes.begin(); it != meshNodes.end();)
    {
        MeshInstanceNode * mesh = *it;
        bool nodeIn = false;
        for (int k = 0; k < 4; ++k)
        {
            const AABBox3 & bbox = mesh->GetWTMaximumBoundingBox();
            if (childBoxes[k].IsInside(bbox))
            {
                childCount[k]++;
                childLists[k].push_back(mesh);
                realChildBox[k].AddAABBox(bbox);
                nodeIn = true;
                break;
            }
        }
        if (nodeIn)
        {
            it = meshNodes.erase(it);
        }else
        {
            it++;
        }
        
    }
    
    //for (each new node where number of nodes inside is not 0 build recursively) 
    for (int k = 0; k < 4; ++k)
    {
        if (childCount[k] > 0)
        {
            nodeCount++;
            node->children[k] = cache.New();
            node->children[k]->SetBoundingBox(realChildBox[k]);
            BuildRecursive(node->children[k], childLists[k]);
        }
    }    
    
    // all objects that are not in childs remains in this node
    for (List<MeshInstanceNode*>::iterator it = meshNodes.begin(); it != meshNodes.end(); ++it)
    {
        node->objectsInside.push_back(SafeRetain(*it));
    }
}
Beispiel #8
0
void EditorScene::CheckNodes(Entity * curr)
{
	if(NULL != curr)
	{
		bool newDebugComp = false;
		DebugRenderComponent *dbgComp = NULL;

		BaseObject *bulletObject = NULL;
		BulletComponent * bulletComponent = (BulletComponent*)curr->GetComponent(Component::BULLET_COMPONENT);

		if(NULL != bulletComponent)
		{
			bulletObject = bulletComponent->GetBulletObject();
		}

		// create debug render component for all nodes
		dbgComp = (DebugRenderComponent *) curr->GetComponent(Component::DEBUG_RENDER_COMPONENT);
		if(NULL == dbgComp)
		{
			dbgComp = new DebugRenderComponent();
			newDebugComp = true;
			curr->AddComponent(dbgComp);
		}

		// check other debug settings

		// is camera?
		CameraComponent *camComp = (CameraComponent *) curr->GetComponent(Component::CAMERA_COMPONENT);
		if(NULL != camComp)
		{
			// set flags to show it
			if(newDebugComp)
			{
				dbgComp->SetDebugFlags(dbgComp->GetDebugFlags() | DebugRenderComponent::DEBUG_DRAW_CAMERA);
			}

			// create bullet object for camera (allow selecting it)
			/*
			if(NULL == bulletComponent)
			{
				bulletComponent = (BulletComponent*) curr->GetOrCreateComponent(Component::BULLET_COMPONENT);
				bulletComponent->SetBulletObject(new BulletObject(this, collisionWorld, camComp->GetCamera(), camComp->GetCamera()->GetMatrix()));
			}
			*/
		}

		// is light?
		if(NULL != curr->GetComponent(Component::LIGHT_COMPONENT))
		{
			if(newDebugComp)
			{
				dbgComp->SetDebugFlags(dbgComp->GetDebugFlags() | DebugRenderComponent::DEBUG_DRAW_LIGHT_NODE);
			}

			if(NULL == bulletComponent || NULL == bulletObject)
			{
				BulletObject *bObj = new BulletObject(this, collisionWorld, curr, AABBox3(Vector3(), 2.5f), curr->GetWorldTransform());
				bulletComponent = (BulletComponent*) curr->GetOrCreateComponent(Component::BULLET_COMPONENT);
				bulletComponent->SetBulletObject(bObj);
				SafeRelease(bObj);
			}
		}

		// is user node
		if(NULL != curr->GetComponent(Component::USER_COMPONENT))
		{
			if(newDebugComp)
			{
				dbgComp->SetDebugFlags(dbgComp->GetDebugFlags() | DebugRenderComponent::DEBUG_DRAW_USERNODE);
			}

			if(NULL == bulletComponent || NULL == bulletObject)
			{
				BulletObject *bObj = new BulletObject(this, collisionWorld, curr, AABBox3(Vector3(), 2.5f), curr->GetWorldTransform());
				bulletComponent = (BulletComponent*) curr->GetOrCreateComponent(Component::BULLET_COMPONENT);
				bulletComponent->SetBulletObject(bObj);
				SafeRelease(bObj);
			}
		}

		// is render object?
		RenderComponent * renderComponent = (RenderComponent*) curr->GetComponent(Component::RENDER_COMPONENT);
		if(NULL != renderComponent)
		{
			RenderObject *rObj = renderComponent->GetRenderObject();

			if(NULL != rObj && rObj->GetType() != RenderObject::TYPE_LANDSCAPE && curr->IsLodMain(0))
			{
				if(NULL == bulletComponent || NULL == bulletObject)
				{
					BulletObject *bObj = new BulletObject(this, collisionWorld, curr, curr->GetWorldTransform());
					bulletComponent = (BulletComponent*) curr->GetOrCreateComponent(Component::BULLET_COMPONENT);
					bulletComponent->SetBulletObject(bObj);
					SafeRelease(bObj);
				}
			}
		}
	}

	int size = curr->GetChildrenCount();
	for (int i = 0; i < size; i++)
	{
		CheckNodes(curr->GetChild(i));
	}
}
void DebugRenderSystem::Process()
{
    uint32 size = entities.size();
	for(uint32 i = 0; i < size; ++i)
	{
        Entity * entity = entities[i];
        
        DebugRenderComponent * debugRenderComponent = cast_if_equal<DebugRenderComponent*>(entity->GetComponent(Component::DEBUG_RENDER_COMPONENT));
        TransformComponent * transformComponent = cast_if_equal<TransformComponent*>(entity->GetComponent(Component::TRANSFORM_COMPONENT));
        //RenderComponent * renderComponent = cast_if_equal<RenderComponent*>(entity->GetComponent(Component::RENDER_COMPONENT));
        
        Matrix4 worldTransform = /*(*transformComponent->GetWorldTransform()) * */camera->GetMatrix();
        RenderManager::Instance()->SetMatrix(RenderManager::MATRIX_MODELVIEW, camera->GetMatrix());

        AABBox3 debugBoundigBox = entity->GetWTMaximumBoundingBoxSlow();
        uint32 debugFlags = debugRenderComponent->GetDebugFlags();

		// Camera debug draw
		if(debugFlags & DebugRenderComponent::DEBUG_DRAW_CAMERA)
		{
			CameraComponent * entityCameraComp = (CameraComponent *) entity->GetComponent(Component::CAMERA_COMPONENT);

			if(NULL != entityCameraComp)
			{
				Camera* entityCamera = entityCameraComp->GetCamera();
				if(NULL != entityCamera && camera != entityCamera)
				{
					Color camColor(0.0f, 1.0f, 0.0f, 1.0f);
					Vector3 camPos = entityCamera->GetPosition();
					//Vector3 camDirect = entityCamera->GetDirection();
					AABBox3 camBox(camPos, 2.5f);

					// If this is clip camera - show it as red camera
					if (entityCamera == entity->GetScene()->GetClipCamera()) camColor = Color(1.0f, 0.0f, 0.0f, 1.0f);

					RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
					RenderManager::Instance()->SetState(RenderState::STATE_COLORMASK_ALL | RenderState::STATE_DEPTH_WRITE);
					RenderManager::Instance()->SetColor(camColor);

					RenderHelper::Instance()->DrawBox(camBox, 2.5f);

					RenderManager::Instance()->SetState(RenderState::DEFAULT_3D_STATE);
					RenderManager::Instance()->ResetColor();

					debugBoundigBox = camBox;
				}
			}
		}

		// UserNode debug draw
		if(debugFlags & DebugRenderComponent::DEBUG_DRAW_USERNODE)
		{
			if(NULL != entity->GetComponent(Component::USER_COMPONENT))
			{
				Color dcColor(0.0f, 0.0f, 1.0f, 1.0f);
				AABBox3 dcBox(Vector3(), 1.0f);

				Matrix4 prevMatrix = RenderManager::Instance()->GetMatrix(RenderManager::MATRIX_MODELVIEW);
				Matrix4 finalMatrix = transformComponent->GetWorldTransform() * prevMatrix;
				RenderManager::Instance()->SetMatrix(RenderManager::MATRIX_MODELVIEW, finalMatrix);

				RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
				RenderManager::Instance()->SetState(RenderState::STATE_COLORMASK_ALL | RenderState::STATE_DEPTH_WRITE | RenderState::STATE_DEPTH_TEST);

				RenderManager::Instance()->SetColor(1.f, 1.f, 0, 1.0f);
				RenderHelper::Instance()->DrawLine(Vector3(0, 0, 0), Vector3(1.f, 0, 0));
				RenderManager::Instance()->SetColor(1.f, 0, 1.f, 1.0f);
				RenderHelper::Instance()->DrawLine(Vector3(0, 0, 0), Vector3(0, 1.f, 0));
				RenderManager::Instance()->SetColor(0, 1.f, 1.f, 1.0f);
				RenderHelper::Instance()->DrawLine(Vector3(0, 0, 0), Vector3(0, 0, 1.f));

				RenderManager::Instance()->SetColor(dcColor);
				RenderHelper::Instance()->DrawBox(dcBox);

				RenderManager::Instance()->SetState(RenderState::DEFAULT_3D_STATE);
				RenderManager::Instance()->ResetColor();
				RenderManager::Instance()->SetMatrix(RenderManager::MATRIX_MODELVIEW, prevMatrix);

				dcBox.GetTransformedBox(transformComponent->GetWorldTransform(), debugBoundigBox);
			}
		}

		// LightNode debug draw
		if (debugFlags & DebugRenderComponent::DEBUG_DRAW_LIGHT_NODE)
		{
			LightComponent *lightComp = (LightComponent *) entity->GetComponent(Component::LIGHT_COMPONENT);

			if(NULL != lightComp)
			{
				Light* light = lightComp->GetLightObject();

				if(NULL != light)
				{
					Vector3 lPosition = light->GetPosition();

					RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
					RenderManager::Instance()->SetState(RenderState::STATE_COLORMASK_ALL | RenderState::STATE_DEPTH_WRITE);
					RenderManager::Instance()->SetColor(1.0f, 1.0f, 0.0f, 1.0f);

					switch (light->GetType())
					{
					case Light::TYPE_DIRECTIONAL:
						{
							Vector3 lDirection = light->GetDirection();

							RenderHelper::Instance()->DrawArrow(lPosition, lPosition + lDirection * 10, 2.5f);
							RenderHelper::Instance()->DrawBox(AABBox3(lPosition, 0.5f), 1.5f);

							debugBoundigBox = AABBox3(lPosition, 2.5f);
						}
						break;
					default:
						{
							AABBox3 lightBox(lPosition, 2.5f);
							RenderHelper::Instance()->DrawBox(lightBox, 2.5f);

							debugBoundigBox = lightBox;
						}
						break;
					}

					RenderManager::Instance()->SetState(RenderState::DEFAULT_3D_STATE);
					RenderManager::Instance()->ResetColor();
				}
			}
		}
        
        if ((debugFlags & DebugRenderComponent::DEBUG_DRAW_AABOX_CORNERS))
        {            
            RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
            RenderManager::Instance()->SetState(RenderState::STATE_COLORMASK_ALL | RenderState::STATE_DEPTH_WRITE | RenderState::STATE_DEPTH_TEST);
            RenderManager::Instance()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
            RenderHelper::Instance()->DrawCornerBox(debugBoundigBox, 1.5f);
            RenderManager::Instance()->SetState(RenderState::DEFAULT_3D_STATE);
            RenderManager::Instance()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
            //		RenderManager::Instance()->SetMatrix(RenderManager::MATRIX_MODELVIEW, prevMatrix);
        }
        
        if (debugFlags & DebugRenderComponent::DEBUG_DRAW_RED_AABBOX)
        {
            RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
            RenderManager::Instance()->SetState(RenderState::STATE_COLORMASK_ALL | RenderState::STATE_DEPTH_WRITE);
            RenderManager::Instance()->SetColor(1.0f, 0.0f, 0.0f, 1.0f);
            RenderHelper::Instance()->DrawBox(debugBoundigBox, 1.5f);
            RenderManager::Instance()->SetState(RenderState::DEFAULT_3D_STATE);
            RenderManager::Instance()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
        }
        

        // UserNode Draw
#if 0
       	
        if (debugFlags & DEBUG_DRAW_USERNODE)
        {
            Matrix4 prevMatrix = RenderManager::Instance()->GetMatrix(RenderManager::MATRIX_MODELVIEW);
            Matrix4 finalMatrix = worldTransform * prevMatrix;
            RenderManager::Instance()->SetMatrix(RenderManager::MATRIX_MODELVIEW, finalMatrix);
            
            RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
            RenderManager::Instance()->SetState(RenderStateBlock::STATE_COLORMASK_ALL | RenderStateBlock::STATE_DEPTH_WRITE | RenderStateBlock::STATE_DEPTH_TEST);
            RenderManager::Instance()->SetColor(0, 0, 1.0f, 1.0f);
            RenderHelper::Instance()->DrawBox(drawBox);
            RenderManager::Instance()->SetColor(1.f, 1.f, 0, 1.0f);
            RenderHelper::Instance()->DrawLine(Vector3(0, 0, 0), Vector3(1.f, 0, 0));
            RenderManager::Instance()->SetColor(1.f, 0, 1.f, 1.0f);
            RenderHelper::Instance()->DrawLine(Vector3(0, 0, 0), Vector3(0, 1.f, 0));
            RenderManager::Instance()->SetColor(0, 1.f, 1.f, 1.0f);
            RenderHelper::Instance()->DrawLine(Vector3(0, 0, 0), Vector3(0, 0, 1.f));
            RenderManager::Instance()->SetState(RenderStateBlock::DEFAULT_3D_STATE);
            RenderManager::Instance()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
            RenderManager::Instance()->SetMatrix(RenderManager::MATRIX_MODELVIEW, prevMatrix);
        }
#endif
        
#if 0
        // ParticleEffectNode
        if (debugFlags != DEBUG_DRAW_NONE)
        {
            if (!(flags & SceneNode::NODE_VISIBLE))return;
            
            RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
            RenderManager::Instance()->SetState(RenderStateBlock::STATE_COLORMASK_ALL | RenderStateBlock::STATE_DEPTH_WRITE);
            
            Vector3 position = Vector3(0.0f, 0.0f, 0.0f) * GetWorldTransform();
            Matrix3 rotationPart(GetWorldTransform());
            Vector3 direction = Vector3(0.0f, 0.0f, 1.0f) * rotationPart;
            direction.Normalize();
            
            RenderManager::Instance()->SetColor(0.0f, 0.0f, 1.0f, 1.0f);
            
            RenderHelper::Instance()->DrawLine(position, position + direction * 10, 2.f);
            
            RenderManager::Instance()->SetState(RenderStateBlock::DEFAULT_3D_STATE);
            RenderManager::Instance()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
        }
#endif
        
    }
}