forked from speed-dreams/speed-dreams-code
OSG, working on EM
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5503 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 1580e066f4f6b09ca624c74fd9d61316a523c374 Former-commit-id: 0aeae13eafbce214a8fae11b190a3b65f9328521
This commit is contained in:
parent
b328f7a882
commit
2032fe0f73
3 changed files with 131 additions and 5 deletions
|
@ -49,7 +49,7 @@ private :
|
|||
osg::Node *pCar;
|
||||
osg::StateSet* stateset;
|
||||
osg::ref_ptr<osg::Uniform> diffuseMap;
|
||||
//osg::Uniform * normalMap;
|
||||
osg::Uniform * reflectionMap;
|
||||
osg::ref_ptr<osg::Uniform> specularColor;
|
||||
osg::ref_ptr<osg::Uniform> lightVector;
|
||||
osg::ref_ptr<osg::Uniform> lightPower;
|
||||
|
@ -77,8 +77,8 @@ public :
|
|||
|
||||
diffuseMap = new osg::Uniform("diffusemap", 0 );
|
||||
stateset->addUniform(diffuseMap);
|
||||
// normalMap = new osg::Uniform("normalmap", 1 );
|
||||
// stateset->addUniform(normalMap);
|
||||
reflectionMap = new osg::Uniform("reflectionmap", 2 );
|
||||
stateset->addUniform(reflectionMap);
|
||||
specularColor = new osg::Uniform("specularColor", osg::Vec4(0.8f,0.8f,0.8f,1.0f));
|
||||
stateset->addUniform(specularColor);
|
||||
/*lightVector = new osg::Uniform("lightvector",osg::Vec3());
|
||||
|
@ -323,6 +323,8 @@ osg::Node *SDCar::loadCar(tCarElt *car)
|
|||
if (SHADOW_TECHNIQUE == 0)
|
||||
this->car_root->addChild(this->initOcclusionQuad(car));
|
||||
|
||||
// car_root->setNodeMask(1);
|
||||
|
||||
return this->car_root;
|
||||
}
|
||||
|
||||
|
@ -411,6 +413,18 @@ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
|
|||
return root.get();
|
||||
}
|
||||
|
||||
void SDCar::deactivateCar(tCarElt*car){
|
||||
if(this->car == car){
|
||||
this->car_root->setNodeMask(0);
|
||||
}
|
||||
}
|
||||
|
||||
void SDCar::activateCar(tCarElt*car){
|
||||
if(this->car == car){
|
||||
this->car_root->setNodeMask(1);
|
||||
}
|
||||
}
|
||||
|
||||
void SDCar::updateCar()
|
||||
{
|
||||
osg::Vec3 p;
|
||||
|
@ -448,6 +462,10 @@ void SDCar::updateShadingParameters(osg::Matrixf modelview){
|
|||
shader->update(modelview);
|
||||
}
|
||||
|
||||
void SDCar::setReflectionMap(osg::ref_ptr<osg::TextureCubeMap> map){
|
||||
car_branch->getOrCreateStateSet()->setTextureAttributeAndModes(2,map,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
|
||||
}
|
||||
|
||||
SDCars::SDCars(void)
|
||||
{
|
||||
cars_branch = new osg::Group;
|
||||
|
@ -480,6 +498,37 @@ void SDCars::loadCars(tSituation * pSituation)
|
|||
return;;
|
||||
}
|
||||
|
||||
void SDCars::deactivateCar(tCarElt*car){
|
||||
std::vector<SDCar *>::iterator it;
|
||||
for(it = the_cars.begin(); it!= the_cars.end(); it++)
|
||||
{
|
||||
(*it)->deactivateCar(car);
|
||||
}
|
||||
}
|
||||
|
||||
void SDCars::activateCar(tCarElt*car){
|
||||
std::vector<SDCar *>::iterator it;
|
||||
for(it = the_cars.begin(); it!= the_cars.end(); it++)
|
||||
{
|
||||
(*it)->activateCar(car);
|
||||
}
|
||||
}
|
||||
|
||||
SDCar * SDCars::getCar(tCarElt*car){
|
||||
std::vector<SDCar *>::iterator it;
|
||||
SDCar * res;
|
||||
for(it = the_cars.begin(); it!= the_cars.end(); it++)
|
||||
{
|
||||
if((*it)->isCar(car)){
|
||||
res = *it;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SDCars::updateCars()
|
||||
{
|
||||
std::vector<SDCar *>::iterator it;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <raceman.h>
|
||||
#include <vector>
|
||||
|
||||
#include <osg/TextureCubeMap>
|
||||
|
||||
#include "OsgWheel.h"
|
||||
|
||||
class SDCarShader;
|
||||
|
@ -42,10 +44,18 @@ class SDCar
|
|||
//osg::ref_ptr<osg::MatrixTransform> initWheel(int wheelIndec, const char *wheel_mod_name);
|
||||
osg::ref_ptr<osg::Node> initOcclusionQuad(tCarElt *car);
|
||||
|
||||
|
||||
public :
|
||||
osg::Node *loadCar(tCarElt *car);
|
||||
void deactivateCar(tCarElt*car);
|
||||
inline bool isCar(tCarElt*c){
|
||||
return c==car;
|
||||
}
|
||||
|
||||
void activateCar(tCarElt*car);
|
||||
void updateCar();
|
||||
void updateShadingParameters(osg::Matrixf modelview);
|
||||
void setReflectionMap(osg::ref_ptr<osg::TextureCubeMap> map);
|
||||
};
|
||||
|
||||
class SDCars
|
||||
|
@ -63,6 +73,9 @@ class SDCars
|
|||
|
||||
void loadCars(tSituation * pSituation);
|
||||
void updateCars();
|
||||
void deactivateCar(tCarElt*car);
|
||||
void activateCar(tCarElt*car);
|
||||
SDCar *getCar(tCarElt*car);
|
||||
void unLoad();
|
||||
void updateShadingParameters(osg::Matrixf modelview);
|
||||
osg::Node* getCarsNode(){ return cars_branch.get(); }
|
||||
|
|
|
@ -25,10 +25,56 @@
|
|||
|
||||
#include "OsgReflectionMapping.h"
|
||||
|
||||
#include "OsgCar/OsgCar.h"
|
||||
#include "OsgMain.h"
|
||||
|
||||
#include <car.h>
|
||||
|
||||
|
||||
|
||||
class CameraPreCallback : public osg::Camera::DrawCallback
|
||||
{
|
||||
private:
|
||||
tCarElt * car;
|
||||
public:
|
||||
|
||||
void setCar(tCarElt *c){
|
||||
car = c;
|
||||
}
|
||||
|
||||
virtual void operator()(const osg::Camera& cam) const
|
||||
{
|
||||
|
||||
SDCars * cars = (SDCars *)getCars();
|
||||
|
||||
cars->deactivateCar(car);
|
||||
}
|
||||
};
|
||||
|
||||
class CameraPostCallback : public osg::Camera::DrawCallback
|
||||
{
|
||||
private:
|
||||
tCarElt * car;
|
||||
public:
|
||||
|
||||
void setCar(tCarElt *c){
|
||||
car = c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void operator()(const osg::Camera& cam) const
|
||||
{
|
||||
|
||||
SDCars * cars = (SDCars *)getCars();
|
||||
|
||||
cars->activateCar(car);
|
||||
}
|
||||
};
|
||||
|
||||
CameraPreCallback * pre_cam = new CameraPreCallback;
|
||||
CameraPostCallback * post_cam = new CameraPostCallback;
|
||||
|
||||
|
||||
SDReflectionMapping::SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m_sceneroot){
|
||||
|
||||
|
@ -36,7 +82,7 @@ SDReflectionMapping::SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m
|
|||
|
||||
reflectionMap = new osg::TextureCubeMap;
|
||||
reflectionMap->setTextureSize( 256, 256 );
|
||||
reflectionMap->setInternalFormat( GL_RGB );
|
||||
reflectionMap->setInternalFormat( GL_RGBA);
|
||||
|
||||
camerasRoot = new osg::Group;
|
||||
|
||||
|
@ -46,6 +92,7 @@ SDReflectionMapping::SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m
|
|||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setViewport( 0, 0, 256, 256 );
|
||||
camera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
|
||||
//camera->setClearColor(osg::Vec4(0.0,0.0,0.0,1.0));
|
||||
|
||||
camera->setRenderOrder( osg::Camera::PRE_RENDER );
|
||||
camera->setRenderTargetImplementation(
|
||||
|
@ -55,6 +102,9 @@ SDReflectionMapping::SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m
|
|||
camera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
|
||||
camera->addChild( m_sceneroot );
|
||||
|
||||
camera->setPreDrawCallback(pre_cam);
|
||||
camera->setPostDrawCallback(post_cam);
|
||||
|
||||
|
||||
//camera->setProjectionMatrixAsOrtho(,1,-1,1,0,1000000);
|
||||
|
||||
|
@ -62,18 +112,32 @@ SDReflectionMapping::SDReflectionMapping(SDScreens *s, osg::ref_ptr<osg::Node> m
|
|||
//camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
camerasRoot->addChild(camera);
|
||||
cameras.push_back(camera);
|
||||
//camera->setNodeMask(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//cameras[4]->setNodeMask(1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool st = false;
|
||||
void SDReflectionMapping::update(){
|
||||
|
||||
tCarElt * car = screens->getActiveView()->getCurrentCar();
|
||||
|
||||
SDCars * cars = (SDCars *)getCars();
|
||||
SDCar * sdcar = cars->getCar(car);
|
||||
|
||||
if(!st){
|
||||
sdcar->setReflectionMap(reflectionMap);
|
||||
st =true;
|
||||
}
|
||||
|
||||
pre_cam->setCar(car);
|
||||
post_cam->setCar(car);
|
||||
|
||||
sgVec3 P, p;
|
||||
osg::Vec3 eye,center,up;
|
||||
|
||||
|
|
Loading…
Reference in a new issue