コード例 #1
0
ファイル: IHM.cpp プロジェクト: GP-S/HOTS
void IHM::PolycodeGUI::IHM::createLights() {
    Entity *lights = new Entity();

    scene->addChild ( lights );

    SceneLight *light = new SceneLight ( SceneLight::SPOT_LIGHT, scene, 4000 );
    light->setPosition ( 10,120,0 );
    light->setLightColor ( 1,1,1 );
    scene->addLight ( light );
    lights->addChild ( light );
    light->lookAt ( Vector3 ( 0,0,0 ) );
    light->setScale ( 2,3,2 );
    light->enableShadows ( true );
    light->getSpotlightCamera()->frustumCulling = false;

    SceneLight *light2 = new SceneLight ( SceneLight::POINT_LIGHT, scene, 15000 );
    light2->setPosition ( -200,200,0 );
    light2->setLightColor ( 1,1,1 );
    scene->addLight ( light2 );
    lights->addChild ( light2 );
    light2->lookAt ( Vector3 ( 0,80,0 ) );
    light2->enableShadows ( true );

    light2->getSpotlightCamera()->frustumCulling = false;

    SceneLight *light3 = new SceneLight ( SceneLight::POINT_LIGHT, scene, 15000 );
    light3->setPosition ( 200,200,0 );
    light3->setLightColor ( 1,1,1 );
    scene->addLight ( light3 );
    lights->addChild ( light3 );
    light3->lookAt ( Vector3 ( 0,80,0 ) );
    light3->enableShadows ( true );

    light3->getSpotlightCamera()->frustumCulling = false;
}
コード例 #2
0
ファイル: shader.cpp プロジェクト: leidav/raytracer
float  Shader::specular(const Vec3 &pos,const Vec3 &normal,
			const SceneLight &light,float hardness)
{
	Vec3 h;
	Vec3 v=pos*-1;
	Vec3 l=light.getPos()-pos;
	v.normalize();
	l.normalize();
	h=l+v;
	h.normalize();

	return pow(h*normal,hardness);
}
コード例 #3
0
ファイル: PolySceneLight.cpp プロジェクト: Anwesh43/Polycode
void SceneLight::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
    Entity::applyClone(clone, deepClone, ignoreEditorOnly);
    SceneLight *cloneLight = (SceneLight*) clone;
    
    cloneLight->setAttenuation(constantAttenuation, linearAttenuation, quadraticAttenuation);
    cloneLight->setIntensity(intensity);
    cloneLight->lightColor = lightColor;
    cloneLight->specularLightColor = specularLightColor;
    cloneLight->enableShadows(shadowsEnabled, shadowMapRes);
    cloneLight->setShadowMapFOV(shadowMapFOV);
    cloneLight->setSpotlightProperties(spotlightCutoff, spotlightExponent);
    cloneLight->setLightType(type);
}
コード例 #4
0
ファイル: shader.cpp プロジェクト: leidav/raytracer
float Shader::diffuse(const Vec3 &pos,const Vec3 &normal,const SceneLight &light)
{
	Vec3 light_pos;
	Vec3 dir;

	light_pos=light.getPos();
	dir=light_pos-pos;
	dir.normalize();

	float diff=(normal*dir);
	if(diff<0) {
		diff=0.0f;
	}
	return diff;
}
コード例 #5
0
ファイル: HelloPolycodeApp.cpp プロジェクト: RobLach/Polycode
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
    	core = new SDLCore(view, 640,480,false,0,90);	  
	CoreServices::getInstance()->getResourceManager()->addArchive("default.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);

	CoreServices::getInstance()->getResourceManager()->addDirResource("Resources", false);

	Scene *scene = new Scene();
	ScenePrimitive *ground = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 5,5);
	ground->setMaterialByName("GroundMaterial");
	scene->addEntity(ground);

	ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1,1,1);
	box->setMaterialByName("CubeMaterial");
	box->setPosition(0.0, 0.5, 0.0);
	scene->addEntity(box);
	
	SceneLight *light = new SceneLight(SceneLight::AREA_LIGHT, scene, 3);
	light->setPosition(1,2,1);
	scene->addLight(light);

	scene->getDefaultCamera()->setPosition(7,7,7);
	scene->getDefaultCamera()->lookAt(Vector3(0,0,0));
}
コード例 #6
0
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {

#ifdef __APPLE__
	core = new CocoaCore(view, 640,480,false,false,0,0,90);	  
#else
	core = new SDLCore(view, 640,480,false,false,0,0,90);	  
#endif

	CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
	CoreServices::getInstance()->getResourceManager()->addDirResource("Resources", false);	

	Scene *scene = new Scene();
	ScenePrimitive *ground = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 5,5);
	ground->setMaterialByName("GroundMaterial");
	scene->addEntity(ground);
	
	scene->getDefaultCamera()->setPosition(7,7,7);
	scene->getDefaultCamera()->lookAt(Vector3(0,0,0));	
	
	Mesh *mesh = new Mesh(Mesh::QUAD_MESH);
//	mesh->createBox(1, 1, 1);	
	mesh->createTorus(0.3,0.2,10,10);

	
	SceneParticleEmitter *emitter = new SceneParticleEmitter("Default", scene,
		Particle::MESH_PARTICLE, ParticleEmitter::CONTINUOUS_EMITTER, 4, 100,
		Vector3(0.0,1.0,0.0), Vector3(0.0,0.0,0.0), Vector3(0.3, 0.0, 0.3),
		Vector3(1.5,1.5,1.5), mesh);
			
	emitter->useScaleCurves = true;
	emitter->scaleCurve.addControlPoint2d(0, 0.1);
	emitter->scaleCurve.addControlPoint2d(0.5, 0.3);
	emitter->scaleCurve.addControlPoint2d(1, 0);	
	
	scene->addEntity(emitter);	

	SceneLight *light = new SceneLight(SceneLight::AREA_LIGHT, scene, 5);
	light->setPosition(3,2,3);
	light->setLightColor(1,0,0);
	scene->addLight(light);

	light = new SceneLight(SceneLight::AREA_LIGHT, scene, 5);
	light->setPosition(-3,2,3);
	light->setLightColor(0,1,0);
	scene->addLight(light);

	light = new SceneLight(SceneLight::AREA_LIGHT, scene, 5);
	light->setPosition(-3,2,-3);
	light->setLightColor(0,0,1);
	scene->addLight(light);

	light = new SceneLight(SceneLight::AREA_LIGHT, scene, 5);
	light->setPosition(3,2,-3);
	light->setLightColor(1,0,1);
	scene->addLight(light);

	light = new SceneLight(SceneLight::SPOT_LIGHT, scene, 4);
	light->setPosition(0,2,2);
	light->setSpotlightProperties(30,6);
	light->setLightColor(1,1,0);
	scene->addLight(light);
	light->lookAt(Vector3(0,0,0));
	light->enableShadows(true);
		
	light = new SceneLight(SceneLight::SPOT_LIGHT, scene, 4);
	light->setPosition(0,2,-2);
	light->setSpotlightProperties(30,6);
	light->setLightColor(0,1,1);
	scene->addLight(light);
	light->lookAt(Vector3(0,0,0));
	light->enableShadows(true);

}
コード例 #7
0
ファイル: HelloPolycodeApp.cpp プロジェクト: 0x81c/Polycode
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {

	core = new POLYCODE_CORE(view, 640,480,false,true,6,16,90, 0, true);

	CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
	CoreServices::getInstance()->getResourceManager()->addDirResource("Resources", false);
	
	scene = new Scene();
	ScenePrimitive *ground = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 5,5);
	ground->setMaterialByName("GroundMaterial");
	scene->addEntity(ground);

	torus = new ScenePrimitive(ScenePrimitive::TYPE_TORUS, 0.8,0.3,30,20);
	torus->setMaterialByName("CubeMaterial");
	torus->setPosition(0.0, 0.5, 0.0);
	scene->addEntity(torus);

	SceneLight *light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
	light->setPosition(3,2,3);
	light->setLightColor(1,0,0);
	scene->addLight(light);

	light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
	light->setPosition(-3,2,3);
	light->setLightColor(0,1,0);
	scene->addLight(light);

	light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
	light->setPosition(-3,2,-3);
	light->setLightColor(0,0,1);
	scene->addLight(light);

	light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
	light->setPosition(3,2,-3);
	light->setLightColor(1,0,1);
	scene->addLight(light);
    
    lights = new Entity();
    scene->addChild(lights);
    
	light = new SceneLight(SceneLight::SPOT_LIGHT, scene, 4);
	light->setPosition(0,4,1);
	light->setLightColor(1,1,0);
	scene->addLight(light);
	lights->addChild(light);
	light->lookAt(Vector3(0,0,0));
	light->enableShadows(true);
    light->getSpotlightCamera()->frustumCulling = false;

	light = new SceneLight(SceneLight::SPOT_LIGHT, scene, 4);
	light->setPosition(0,4,-1);
	light->setLightColor(0,1,1);
	scene->addLight(light);
	lights->addChild(light);
	light->lookAt(Vector3(0,0,0));
	light->enableShadows(true);
    light->getSpotlightCamera()->frustumCulling = false;
    

    cameraRotation = 0.0;
}
コード例 #8
0
ファイル: PolyScene.cpp プロジェクト: Flapstah/Polycode
void Scene::Render(Camera *targetCamera) {
	
	if(!targetCamera && !activeCamera)
		return;
	
	if(!targetCamera)
		targetCamera = activeCamera;
	
	// prepare lights...
	for(int i=0; i<entities.size();i++) {
		entities[i]->doUpdates();		
		entities[i]->updateEntityMatrix();
	}	
	
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	targetCamera->rebuildTransformMatrix();
		
	if(useClearColor)
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b);	
	
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		
	
	CoreServices::getInstance()->getRenderer()->clearLights();
	
	for(int i=0; i < lights.size(); i++) {
		SceneLight *light = lights[i];
		if(!light->enabled)
			continue;
			
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;		
		direction.y = 0;
		direction.z = -1;
		
		
		direction = light->getConcatenatedMatrix().rotateVector(direction);
		direction.Normalize();
		
		Texture *shadowMapTexture = NULL;
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
//				textureMatrix.identity();
				
				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );
				
								
				light->renderDepthMap(this);
				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
				matrixPtr = &textureMatrix;				
			//	CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
				shadowMapTexture = light->getZBufferTexture();
			}
		}
		
		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
		CoreServices::getInstance()->getRenderer()->addLight(light->getLightImportance(), position, direction, light->getLightType(), light->lightColor, light->specularLightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr, shadowMapTexture);
	}	
	
	targetCamera->doCameraTransform();
	targetCamera->buildFrustrumPlanes();
	
	if(targetCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->_setOrthoMode();
	}
	
	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);	
	if(fogEnabled) {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, fogDensity, fogStartDepth, fogEndDepth);
	} else {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, 0.0, fogStartDepth, fogEndDepth);	
	}
	
	
	for(int i=0; i<entities.size();i++) {
		if(entities[i]->getBBoxRadius() > 0) {
			if(targetCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
				entities[i]->transformAndRender();
		} else {
			entities[i]->transformAndRender();		
		}
	}
	
	if(targetCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->setPerspectiveMode();
	}
	
}
コード例 #9
0
ファイル: PolyGenericScene.cpp プロジェクト: aaajiao/Polycode
void GenericScene::Render() {
	
	if(!defaultCamera)
		return;
	
	// prepare lights...
	for(int i=0; i<entities.size();i++) {
		entities[i]->doUpdates();		
		entities[i]->updateEntityMatrix();
	}	
	
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	defaultCamera->rebuildTransformMatrix();
	
	if(virtualScene)
		return;
	
	if(useClearColor)
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b);	
	
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		

	CoreServices::getInstance()->getRenderer()->clearLights();
	
	for(int i=0; i < lights.size(); i++) {
		
		SceneLight *light = lights[i];
		
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;		
		direction.y = 1;
		direction.z = 0;

		direction = light->getConcatenatedMatrix().rotateVector(direction);
		direction.Normalize();
		
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
				textureMatrix.identity();

				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );

				textureMatrix =  defaultCamera->getConcatenatedMatrix() * light->getLightViewMatrix() * matTexAdj;
			
				matrixPtr = &textureMatrix;
				light->renderDepthMap(this);
				CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
			}
		}

		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
		CoreServices::getInstance()->getRenderer()->addLight(position, direction, light->getLightType(), light->lightColor, light->getDistance(), light->getIntensity(), matrixPtr);
	}	
	
	defaultCamera->doCameraTransform();
	defaultCamera->buildFrustrumPlanes();
	
	if(defaultCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->_setOrthoMode();
	}
	
	for(int i=0; i<entities.size();i++) {
		if(entities[i]->getBBoxRadius() > 0) {
			if(defaultCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
				entities[i]->transformAndRender();
		} else {
			entities[i]->transformAndRender();		
		}
	}
	
	if(defaultCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->setPerspectiveMode();
	}
	
}
コード例 #10
0
Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entity *targetEntity, int entityFileVersion) {

	Entity *entity = NULL;

	ObjectEntry *entityType = (*entry)["type"];
	if(entityType) {
        if(entityType->stringVal == "SceneEntityInstance") {
            ObjectEntry *instanceEntry = (*entry)["SceneEntityInstance"];
            String filePath = (*instanceEntry)["filePath"]->stringVal;
            SceneEntityInstance *instance = new SceneEntityInstance(parentScene, filePath);
            entity = instance;
         } else if(entityType->stringVal == "SceneCurve") {
			ObjectEntry *curveEntry = (*entry)["SceneCurve"];
             
             SceneCurve *curve = new SceneCurve();
             
            if(curveEntry) {
                curve->renderCurve = (*curveEntry)["render"]->boolVal;
                curve->curveResolution = (*curveEntry)["resolution"]->intVal;                
                parseObjectIntoCurve((*curveEntry)["curve"], curve->getCurve());
            }
             
             entity = curve;
             
         } else if(entityType->stringVal == "SceneSprite") {

			ObjectEntry *spriteEntry = (*entry)["SceneSprite"];
			String spriteSetName = (*spriteEntry)["sprite_set"]->stringVal;

             SpriteSet *spriteSet = (SpriteSet*)CoreServices::getInstance()->getResourceManager()->getResourcePoolByName(spriteSetName);
             
             if(spriteSet) {
                 SceneSprite *sprite = new SceneSprite(spriteSet);
                 
                 String spriteName = (*spriteEntry)["sprite"]->stringVal;
                 sprite->setSpriteByName(spriteName);

                 
                 String stateName = (*spriteEntry)["state"]->stringVal;
                 
                 if(sprite->getCurrentSprite()) {
                     SpriteState *state = sprite->getCurrentSprite()->getStateByName(stateName);
                     if(state) {
                         sprite->setSpriteState(state, 0, false);
                     }
                     
                     ObjectEntry *randomFrameEntry = (*spriteEntry)["random_frame"];
                     if(randomFrameEntry) {
                        sprite->setStartOnRandomFrame(randomFrameEntry->boolVal);
                     }
                     
                 }
                 
                 entity = sprite;
                 applySceneMesh((*entry)["SceneMesh"], sprite);
             }

        } else 	if(entityType->stringVal == "SceneLabel") {
			ObjectEntry *labelEntry = (*entry)["SceneLabel"];
			
			String text = (*labelEntry)["text"]->stringVal;
			String font = (*labelEntry)["font"]->stringVal;
			int size = (*labelEntry)["size"]->intVal;
            Number actualHeight = (*labelEntry)["actualHeight"]->intVal;
			int aaMode = (*labelEntry)["aaMode"]->intVal;
            
			SceneLabel *label = new SceneLabel(text, size, font, aaMode, actualHeight);
            label->setAnchorPoint(0.0, 0.0, 0.0);
            label->snapToPixels = false;
            label->positionAtBaseline = false;
            applySceneMesh((*entry)["SceneMesh"], label);
            
            // RENDERER_TODO
            /*
            if(label->getLocalShaderOptions()) {
                label->getLocalShaderOptions()->clearTexture("diffuse");
                label->getLocalShaderOptions()->addTexture("diffuse", label->getTexture());
            }
            */
            
			entity = label;
        } else if(entityType->stringVal == "SceneParticleEmitter") {
            
			ObjectEntry *emitterEntry = (*entry)["SceneParticleEmitter"];
            SceneParticleEmitter *emitter = new SceneParticleEmitter(1, 1, 1);

            emitter->setParticleType((*emitterEntry)["type"]->intVal);
            emitter->setParticleSpeed((*emitterEntry)["speed"]->NumberVal);
            emitter->setParticleCount((*emitterEntry)["count"]->intVal);
            emitter->setParticleLifetime((*emitterEntry)["lifetime"]->NumberVal);
            emitter->setParticleSize((*emitterEntry)["size"]->NumberVal);
            emitter->setParticlesInWorldSpace((*emitterEntry)["world"]->boolVal);
            emitter->setLoopParticles((*emitterEntry)["loop"]->boolVal);
            
            emitter->setParticleRotationSpeed(Vector3((*emitterEntry)["rX"]->NumberVal, (*emitterEntry)["rY"]->NumberVal, (*emitterEntry)["rZ"]->NumberVal));
            emitter->setGravity(Vector3((*emitterEntry)["gX"]->NumberVal, (*emitterEntry)["gY"]->NumberVal, (*emitterEntry)["gZ"]->NumberVal));
            emitter->setParticleDirection(Vector3((*emitterEntry)["dirX"]->NumberVal, (*emitterEntry)["dirY"]->NumberVal, (*emitterEntry)["dirZ"]->NumberVal));
            emitter->setEmitterSize(Vector3((*emitterEntry)["eX"]->NumberVal, (*emitterEntry)["eY"]->NumberVal, (*emitterEntry)["eZ"]->NumberVal));
            emitter->setDirectionDeviation(Vector3((*emitterEntry)["devX"]->NumberVal, (*emitterEntry)["devY"]->NumberVal, (*emitterEntry)["devZ"]->NumberVal));
            
            emitter->setPerlinEnabled((*emitterEntry)["perlin"]->boolVal);
            if(emitter->getPerlinEnabled()) {
                emitter->setPerlinValue(Vector3((*emitterEntry)["pX"]->NumberVal, (*emitterEntry)["pY"]->NumberVal, (*emitterEntry)["pZ"]->NumberVal));
            }
            
            emitter->useColorCurves = (*emitterEntry)["useColorCurves"]->boolVal;
            emitter->useScaleCurve = (*emitterEntry)["useScaleCurve"]->boolVal;
            
            parseObjectIntoCurve((*emitterEntry)["colorCurveR"], &emitter->colorCurveR);
            parseObjectIntoCurve((*emitterEntry)["colorCurveG"], &emitter->colorCurveG);
            parseObjectIntoCurve((*emitterEntry)["colorCurveB"], &emitter->colorCurveB);
            parseObjectIntoCurve((*emitterEntry)["colorCurveA"], &emitter->colorCurveA);
            parseObjectIntoCurve((*emitterEntry)["scaleCurve"], &emitter->scaleCurve);
            
            applySceneMesh((*entry)["SceneMesh"], emitter);
			entity = emitter;
            
		} else if(entityType->stringVal == "SceneLight") {
            
			ObjectEntry *lightEntry = (*entry)["SceneLight"];
            if(lightEntry) {
                int lightType = (*lightEntry)["type"]->intVal;
                SceneLight *newLight  = new SceneLight(lightType, parentScene, 0);
                
                newLight->setIntensity((*lightEntry)["intensity"]->NumberVal);
                
                ObjectEntry *importanceEntry = (*lightEntry)["importance"];
                if(importanceEntry) {
                    newLight->setLightImportance(importanceEntry->intVal);
                }
                
                newLight->setDiffuseLightColor((*lightEntry)["cR"]->NumberVal, (*lightEntry)["cG"]->NumberVal, (*lightEntry)["cB"]->NumberVal, (*lightEntry)["cA"]->NumberVal);
                newLight->setSpecularLightColor((*lightEntry)["scR"]->NumberVal, (*lightEntry)["scG"]->NumberVal, (*lightEntry)["scB"]->NumberVal, (*lightEntry)["scA"]->NumberVal);

                newLight->setAttenuation((*lightEntry)["cAtt"]->NumberVal, (*lightEntry)["lAtt"]->NumberVal, (*lightEntry)["qAtt"]->NumberVal);
                
                if(newLight->getType() == SceneLight::SPOT_LIGHT) {
                    newLight->setSpotlightProperties((*lightEntry)["spotCutoff"]->NumberVal, (*lightEntry)["spotExponent"]->NumberVal);
                    
                    if((*lightEntry)["shadows"]->boolVal) {
                        newLight->enableShadows(true, (*lightEntry)["shadowmapRes"]->intVal);
                        newLight->setShadowMapFOV((*lightEntry)["shadowmapFOV"]->NumberVal);
                    }
                }
                
                parentScene->addLight(newLight);
                entity = newLight;
            }
 
        } else if(entityType->stringVal == "ScenePrimitive") {
			ObjectEntry *scenePrimitiveEntry = (*entry)["ScenePrimitive"];
			int pType = (*scenePrimitiveEntry)["type"]->intVal;
			Number p1 = (*scenePrimitiveEntry)["p1"]->NumberVal;
			Number p2 = (*scenePrimitiveEntry)["p2"]->NumberVal;
			Number p3 = (*scenePrimitiveEntry)["p3"]->NumberVal;
			Number p4 = (*scenePrimitiveEntry)["p4"]->NumberVal;
			Number p5 = (*scenePrimitiveEntry)["p5"]->NumberVal;
            
			ScenePrimitive *primitive = new ScenePrimitive(pType, p1, p2, p3, p4, p5);
			entity = primitive;
            applySceneMesh((*entry)["SceneMesh"], primitive);
		} else if(entityType->stringVal == "SceneMesh") {
			ObjectEntry *meshEntry = (*entry)["SceneMesh"];
            if(meshEntry) {
                ObjectEntry *fileName = (*meshEntry)["file"];
                if(fileName) {
                    SceneMesh *newMesh = new SceneMesh(fileName->stringVal);
                    applySceneMesh(meshEntry, newMesh);
                    // RENDERER_TODO
                    //newMesh->cacheToVertexBuffer(true);
                    entity = newMesh;
                }
            }
        } else if(entityType->stringVal == "SceneSound") {
			ObjectEntry *soundEntry = (*entry)["SceneSound"];
			
			String filePath = (*soundEntry)["filePath"]->stringVal;
			Number refDistance = (*soundEntry)["refDistance"]->NumberVal;
			Number maxDistance = (*soundEntry)["maxDistance"]->NumberVal;
			Number volume = (*soundEntry)["volume"]->NumberVal;
			Number pitch = (*soundEntry)["pitch"]->NumberVal;
            
			SceneSound *sound = new SceneSound(filePath, refDistance, maxDistance);
			sound->getSound()->setVolume(volume);
			sound->getSound()->setPitch(pitch);
			
            if((*soundEntry)["loopOnLoad"]) {
                bool loopOnLoad = (*soundEntry)["loopOnLoad"]->boolVal;
                sound->setLoopOnLoad(loopOnLoad);
                if(loopOnLoad) {
                    sound->getSound()->Play(true);
                }
            }
            
            
			entity = sound;
        } else if(entityType->stringVal == "Camera") {
			ObjectEntry *cameraEntry = (*entry)["Camera"];
            
			Camera *camera = new Camera(parentScene);
            
            camera->setExposureLevel((*cameraEntry)["exposure"]->NumberVal);
            camera->setClippingPlanes((*cameraEntry)["nearClip"]->NumberVal, (*cameraEntry)["farClip"]->NumberVal);
            camera->setOrthoMode((*cameraEntry)["ortho"]->boolVal);
            
            if(camera->getOrthoMode()) {
				camera->setOrthoSizeMode((*cameraEntry)["sizeMode"]->intVal);
                camera->setOrthoSize((*cameraEntry)["orthoWidth"]->NumberVal, (*cameraEntry)["orthoHeight"]->NumberVal);
            } else {
                camera->setFOV((*cameraEntry)["fov"]->NumberVal);
            }
            
			entity = camera;
		}

        
	}

	if(!entity) {
		if(targetEntity) {
			entity = targetEntity;
		} else {
			entity = new Entity();
		}
	}
	
	entity->ownsChildren = true;

    Vector3 bBox;
	entry->readNumber("bbX", &bBox.x);
	entry->readNumber("bbY", &bBox.y);
	entry->readNumber("bbZ", &bBox.z);
    entity->setLocalBoundingBox(bBox);
    
	entity->color.r = (*entry)["cR"]->NumberVal;
	entity->color.g = (*entry)["cG"]->NumberVal;
	entity->color.b = (*entry)["cB"]->NumberVal;
	entity->color.a = (*entry)["cA"]->NumberVal;


	if(!targetEntity) {	
		entity->setBlendingMode((*entry)["blendMode"]->intVal);

        entity->setScale((*entry)["sX"]->NumberVal, (*entry)["sY"]->NumberVal, (*entry)["sZ"]->NumberVal);
        entity->setPosition((*entry)["pX"]->NumberVal, (*entry)["pY"]->NumberVal, (*entry)["pZ"]->NumberVal);
        
        if(entityFileVersion > 1) {
            entity->setRotationQuat((*entry)["rW"]->NumberVal, (*entry)["rX"]->NumberVal, (*entry)["rY"]->NumberVal, (*entry)["rZ"]->NumberVal);
        } else {
            entity->setRotationEuler(Vector3((*entry)["rX"]->NumberVal, (*entry)["rY"]->NumberVal, (*entry)["rZ"]->NumberVal));
        }
	}
	
	if((*entry)["id"]->stringVal != "") {
		entity->id = (*entry)["id"]->stringVal;
	}
    
    if((*entry)["layerID"]) {
        entity->layerID = (unsigned int)((*entry)["layerID"]->intVal);
    }
	
	String tagString = (*entry)["tags"]->stringVal; 
	
	if(tagString != "") {
		std::vector<String> tags = tagString.split(",");
		for(int i=0; i < tags.size(); i++) {
			entity->addTag(tags[i]);
		}
	}
	
	ObjectEntry *props = (*entry)["props"];
	if(props) {
		for(int i=0; i < props->length; i++) {		
			ObjectEntry *prop = ((*props))[i];		
			if(prop) {
				entity->setEntityProp((*prop)["name"]->stringVal, (*prop)["value"]->stringVal);
			}
		}
	}
														
	ObjectEntry *children = (*entry)["children"];
	
	if(children) {
		for(int i=0; i < children->length; i++) {
			ObjectEntry *childEntry = ((*children))[i];
			ScreenEntity *childEntity = loadObjectEntryIntoEntity(childEntry, NULL, entityFileVersion);
			entity->addChild(childEntity);				
		}
	}

	return entity;
}
コード例 #11
0
ファイル: PolyScene.cpp プロジェクト: carlosmarti/Polycode
void Scene::Render(Camera *targetCamera, Texture *targetFramebuffer) {
    if(!targetCamera && !activeCamera)
        return;
    if(!targetCamera)
        targetCamera = activeCamera;
    
    GPUDrawBuffer *drawBuffer = new GPUDrawBuffer();
    drawBuffer->clearColor = clearColor;
    drawBuffer->clearColorBuffer = useClearColor;
    drawBuffer->clearDepthBuffer = useClearDepth;
    drawBuffer->targetFramebuffer = targetFramebuffer;
    drawBuffer->viewport = targetCamera->getViewport();
    drawBuffer->globalMaterial = overrideMaterial;	
		
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	targetCamera->rebuildTransformMatrix();
    
    drawBuffer->projectionMatrix = targetCamera->createProjectionMatrix();
    drawBuffer->viewMatrix = targetCamera->getConcatenatedMatrix().Inverse();
    drawBuffer->cameraMatrix = targetCamera->getConcatenatedMatrix();
/*
	if(useClearColor) {
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b, clearColor.a);	
	}
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);
*/
	
	for(int i=0; i < lights.size(); i++) {
		SceneLight *light = lights[i];
		if(!light->enabled)
			continue;
			
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;
		direction.y = 0.0;
		direction.z = -1.0;
		direction.Normalize();
		
		direction = light->getConcatenatedMatrix().rotateVector(direction);
		
		Texture *shadowMapTexture = NULL;
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );
				
				light->renderDepthMap(this);
				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
				matrixPtr = &textureMatrix;
				shadowMapTexture = light->getZBufferTexture();
			}
		}
		
		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
        
        
        drawBuffer->lights.push_back(light->getLightInfo());
        drawBuffer->lights[drawBuffer->lights.size()-1].position = position;
        drawBuffer->lights[drawBuffer->lights.size()-1].direction = direction;
	}	
		
    	/*
    if(_doVisibilityChecking) {
        targetCamera->buildFrustumPlanes();
        setEntityVisibility(&rootEntity, targetCamera);
    }
         */
	rootEntity.transformAndRender(drawBuffer, NULL);

    
    renderer->processDrawBuffer(drawBuffer);
    
}
コード例 #12
0
ファイル: PolyScene.cpp プロジェクト: Mr-Nil/Polycode
void Scene::Render(Camera *targetCamera) {	
	if(!targetCamera && !activeCamera)
		return;
    
    renderer->setOverrideMaterial(overrideMaterial);
	
	if(!targetCamera)
		targetCamera = activeCamera;
		
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	targetCamera->rebuildTransformMatrix();
		
	if(useClearColor) {
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b, clearColor.a);	
	}
	if (useClearColor || useClearDepth) {
		CoreServices::getInstance()->getRenderer()->clearScreen(useClearColor, useClearDepth);
	}
	
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		
	
	CoreServices::getInstance()->getRenderer()->clearLights();
	
	for(int i=0; i < lights.size(); i++) {
		SceneLight *light = lights[i];
		if(!light->enabled)
			continue;
			
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;
		direction.y = 0.0;
		direction.z = -1.0;
		direction.Normalize();
		
		direction = light->getConcatenatedMatrix().rotateVector(direction);
		
		Texture *shadowMapTexture = NULL;
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
//				textureMatrix.identity();
				
				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );
				
				light->renderDepthMap(this);
				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
				matrixPtr = &textureMatrix;				
			//	CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
				shadowMapTexture = light->getZBufferTexture();
			}
		}
		
		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
		CoreServices::getInstance()->getRenderer()->addLight(light->getLightImportance(), position, direction, light->getLightType(), light->lightColor, light->specularLightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr, shadowMapTexture);
	}	
		
	targetCamera->doCameraTransform();
    
	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);
	if(fogEnabled) {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, fogDensity, fogStartDepth, fogEndDepth);
	} else {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, 0.0, fogStartDepth, fogEndDepth);	
	}
	
    if(_doVisibilityChecking) {
        targetCamera->buildFrustumPlanes();
        setEntityVisibility(&rootEntity, targetCamera);
    }
	rootEntity.transformAndRender();		
}