forked from speed-dreams/speed-dreams-code
OSG : trying to correct shadow problems
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5471 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 6ff8f500fed121a70cc3d34480446fe4c1bb6a65 Former-commit-id: e8eeb6948fd5169ab98a4f064d5262dbe5439c98
This commit is contained in:
parent
a0a08af4f7
commit
c83c539fbd
2 changed files with 23 additions and 19 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <portability.h>
|
#include <portability.h>
|
||||||
#include <osg/Texture2D>
|
#include <osg/Texture2D>
|
||||||
#include <osg/BlendFunc>
|
#include <osg/BlendFunc>
|
||||||
|
#include <osg/Depth>
|
||||||
#include <osgDB/ReadFile>
|
#include <osgDB/ReadFile>
|
||||||
|
|
||||||
#include <robottools.h>
|
#include <robottools.h>
|
||||||
|
@ -302,9 +303,13 @@ SDCar::loadCar(tCarElt *car)
|
||||||
this->car_branch = transform1.get();
|
this->car_branch = transform1.get();
|
||||||
|
|
||||||
this->car_branch->addChild(wheels.initWheels(car,handle));
|
this->car_branch->addChild(wheels.initWheels(car,handle));
|
||||||
this->car_branch->addChild(this->initOcclusionQuad(car));
|
|
||||||
|
|
||||||
return this->car_branch;
|
|
||||||
|
this->car_root = new osg::Group;
|
||||||
|
car_root->addChild(car_branch);
|
||||||
|
this->car_root->addChild(this->initOcclusionQuad(car));
|
||||||
|
|
||||||
|
return this->car_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GR_SHADOW_POINTS 6
|
#define GR_SHADOW_POINTS 6
|
||||||
|
@ -363,7 +368,7 @@ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car){
|
||||||
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
|
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
|
||||||
colors->push_back( osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );
|
colors->push_back( osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geometry> quad = new osg::Geometry;
|
quad = new osg::Geometry;
|
||||||
quad->setVertexArray( vertices.get() );
|
quad->setVertexArray( vertices.get() );
|
||||||
quad->setNormalArray( normals.get() );
|
quad->setNormalArray( normals.get() );
|
||||||
quad->setNormalBinding( osg::Geometry::BIND_OVERALL );
|
quad->setNormalBinding( osg::Geometry::BIND_OVERALL );
|
||||||
|
@ -413,25 +418,22 @@ void SDCar::updateCar()
|
||||||
|
|
||||||
wheels.updateWheels();
|
wheels.updateWheels();
|
||||||
|
|
||||||
//ugly computation, order to chec
|
|
||||||
osg::Vec3Array::iterator itr;
|
|
||||||
itr = shadowVertices->begin();
|
|
||||||
|
|
||||||
while (itr != shadowVertices->end())
|
|
||||||
{
|
|
||||||
osg::Vec3 vtx = *itr;
|
|
||||||
osg::Vec4 tvtx = osg::Vec4(vtx,1.0f)*mat;
|
|
||||||
tvtx._v[2] = RtTrackHeightG(car->_trkPos.seg, tvtx.x(), tvtx.y())+ 0.0699;
|
|
||||||
osg::Matrix iv = osg::Matrix::inverse(mat);
|
|
||||||
osg::Vec4 vtxw = tvtx*iv;
|
|
||||||
vtxw._v[2] = vtxw.z();
|
|
||||||
itr->set(vtxw.x(), vtxw.y(), vtxw.z());
|
|
||||||
itr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->car_branch->setMatrix(mat);
|
this->car_branch->setMatrix(mat);
|
||||||
|
|
||||||
|
|
||||||
|
//ugly computation,
|
||||||
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
||||||
|
for(uint i=0;i<shadowVertices->size();i++)
|
||||||
|
{
|
||||||
|
osg::Vec3 vtx = (*shadowVertices.get())[i];
|
||||||
|
osg::Vec4 vtx_world = osg::Vec4(vtx,1.0f)*mat;
|
||||||
|
vtx_world._v[2] = RtTrackHeightG(car->_trkPos.seg, vtx_world.x(), vtx_world.y()); //0.01 needed, we have to sort out why
|
||||||
|
vertices->push_back(osg::Vec3(vtx_world.x(), vtx_world.y(), vtx_world.z()));
|
||||||
|
|
||||||
|
}
|
||||||
|
quad->setVertexArray(vertices);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDCar::updateShadingParameters(osg::Matrixf modelview){
|
void SDCar::updateShadingParameters(osg::Matrixf modelview){
|
||||||
|
|
|
@ -32,10 +32,12 @@ class SDCar
|
||||||
{
|
{
|
||||||
private :
|
private :
|
||||||
osg::ref_ptr<osg::MatrixTransform> car_branch;
|
osg::ref_ptr<osg::MatrixTransform> car_branch;
|
||||||
|
osg::ref_ptr<osg::Group> car_root;
|
||||||
tCarElt *car;
|
tCarElt *car;
|
||||||
SDWheels wheels;
|
SDWheels wheels;
|
||||||
SDCarShader * shader;
|
SDCarShader * shader;
|
||||||
osg::ref_ptr<osg::Vec3Array> shadowVertices;
|
osg::ref_ptr<osg::Vec3Array> shadowVertices;
|
||||||
|
osg::ref_ptr<osg::Geometry> quad;
|
||||||
// osg::ref_ptr<osg::MatrixTransform> wheels[4];
|
// osg::ref_ptr<osg::MatrixTransform> wheels[4];
|
||||||
// osg::ref_ptr<osg::MatrixTransform> initWheel(int wheelIndec, const char *wheel_mod_name);
|
// osg::ref_ptr<osg::MatrixTransform> initWheel(int wheelIndec, const char *wheel_mod_name);
|
||||||
osg::ref_ptr<osg::Node> initOcclusionQuad(tCarElt *car);
|
osg::ref_ptr<osg::Node> initOcclusionQuad(tCarElt *car);
|
||||||
|
|
Loading…
Reference in a new issue