From ba3edc6e83893056124f5fead1352a108ade76fc Mon Sep 17 00:00:00 2001 From: torcs-ng Date: Tue, 13 Nov 2012 23:55:21 +0000 Subject: [PATCH] fix load3Dfile for cars & added directory drivers for skins git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5046 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 0e8b9b36d512163098755440f90ed1a2f75f6602 Former-commit-id: d9d6e2983feb7a3135fb5b658b763a46d5950f7e --- src/modules/graphic/osggraph/OsgCar.cpp | 27 ++++++++++----- src/modules/graphic/osggraph/OsgLoader.cpp | 7 ++-- src/modules/graphic/osggraph/OsgLoader.h | 2 +- src/modules/graphic/osggraph/OsgMain.cpp | 39 +++++++++++----------- src/modules/graphic/osggraph/OsgMath.h | 10 ------ src/modules/graphic/osggraph/OsgScene.cpp | 4 +-- 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/modules/graphic/osggraph/OsgCar.cpp b/src/modules/graphic/osggraph/OsgCar.cpp index 8efc8c71d..95b46a5dd 100644 --- a/src/modules/graphic/osggraph/OsgCar.cpp +++ b/src/modules/graphic/osggraph/OsgCar.cpp @@ -40,6 +40,9 @@ osg::ref_ptr SDCar::loadCar(tCarElt *car) const char *param; int lg; char path[256]; + + strncpy(car->_masterModel, GfParmGetStr(car->_carHandle, SECT_GROBJECTS, PRM_TEMPLATE, ""), MAX_NAME_LEN - 1); + car->_masterModel[MAX_NAME_LEN - 1] = 0; // grssgLoaderOptions options; // sgVec3 lightPos; // int lightNum; @@ -62,7 +65,7 @@ osg::ref_ptr SDCar::loadCar(tCarElt *car) const bool bMasterModel = strlen(car->_masterModel) != 0; GfOut("[gr] Init(%d) car %s for driver %s index %d\n", index, car->_carName, car->_modName, car->_driverIndex); - + GfOut("[gr] Init(%d) car %s MasterModel name\n", index, car->_masterModel); lg = 0; lg += snprintf(buf + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;", @@ -121,25 +124,31 @@ osg::ref_ptr SDCar::loadCar(tCarElt *car) //GfOut("HEHEHHEHEHEHHEHHEH %s\n",path); //carEntity = grssgCarLoadAC3D(param, NULL, index); std::string strPath = GetDataDir(); - sprintf(buf, "cars/%s/%s.acc", car->_carName, car->_carName); + if (bMasterModel) + sprintf(buf, "cars/%s/%s.acc", car->_masterModel, car->_masterModel); + else + sprintf(buf, "cars/%s/%s.acc", car->_carName, car->_carName); + strPath+=buf; osgLoader loader; - //GfOut("Chemin Textures : %s\n", m_strTexturePath.c_str()); - //loader.AddSearchPath(m_strTexturePath); - //osg::Node *pCar = loader.Load3dFile("/usr/local/share/games/speed-dreams-2/cars/mp1-cavallo-tr06/mp1-cavallo-tr06-lod1.acc"); - osg::Node *pCar = loader.Load3dFile(strPath); + std::string strTPath = GetDataDir(); + sprintf(buf, "drivers/%s/%d/", car->_modName, car->_driverIndex); + strTPath += buf; + GfOut("Chemin Textures : %s\n", strTPath.c_str()); + loader.AddSearchPath(strTPath); + osg::Node *pCar = loader.Load3dFile(strPath, true); osg::Vec3 p; p[0] = car->_pos_X;//+ car->_drvPos_x; p[1] = car->_pos_Y;//+car->_drvPos_y; p[2] = car->_pos_Z;//+car->_drvPos_z; - // osgXformPnt3(p, car->_posMat); + //osgXformPnt3(p, car->_posMat); osg::ref_ptr transform1 = new osg::MatrixTransform; - /* transform1->setMatrix( osg::Matrix::translate(p[0],p[1], p[2]) );*/ - // transform1->setMatrix( osg::Matrix(flatten(car->pub.posMat)) ); + /* transform1->setMatrix( osg::Matrix::translate(p[0],p[1], p[2]) );*/ + // transform1->setMatrix( osg::Matrix(flatten(car->pub.posMat)) ); transform1->addChild(pCar); //osgcars->addChild(transform1.get()); //GfOut("LE POINTEUR %d\n",osgcars.get()); diff --git a/src/modules/graphic/osggraph/OsgLoader.cpp b/src/modules/graphic/osggraph/OsgLoader.cpp index 83479004f..12a650024 100644 --- a/src/modules/graphic/osggraph/OsgLoader.cpp +++ b/src/modules/graphic/osggraph/OsgLoader.cpp @@ -18,7 +18,7 @@ osgLoader::~osgLoader(void) void osgLoader::AddSearchPath(std::string strPath) { - m_pOpt->getDatabasePathList().push_front(strPath); + m_pOpt->getDatabasePathList().push_back(strPath); } osg::ref_ptr osgLoader::LoadImageFile(std::string strFile) @@ -32,10 +32,13 @@ osg::ref_ptr osgLoader::LoadImageFile(std::string strFile) return Image; } -osg::Node *osgLoader::Load3dFile(std::string strFile) +osg::Node *osgLoader::Load3dFile(std::string strFile, bool car) { osg::Node *pNode = NULL; std::string ext = osgDB::getFileExtension(strFile); + if (car) + m_ACCReader.SetCar(true); + if (ext == "acc" || ext == "ac") { //Use custom ACC file loader diff --git a/src/modules/graphic/osggraph/OsgLoader.h b/src/modules/graphic/osggraph/OsgLoader.h index 25e25ed53..3714bbb3e 100644 --- a/src/modules/graphic/osggraph/OsgLoader.h +++ b/src/modules/graphic/osggraph/OsgLoader.h @@ -8,7 +8,7 @@ public: osgLoader(void); ~osgLoader(void); - osg::Node *Load3dFile(std::string strFile); + osg::Node *Load3dFile(std::string strFile, bool car); osg::ref_ptr LoadImageFile(std::string strFile); void AddSearchPath(std::string strPath); diff --git a/src/modules/graphic/osggraph/OsgMain.cpp b/src/modules/graphic/osggraph/OsgMain.cpp index a4e5bd50e..f0ffc6fc9 100644 --- a/src/modules/graphic/osggraph/OsgMain.cpp +++ b/src/modules/graphic/osggraph/OsgMain.cpp @@ -444,8 +444,6 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen) grWinw = width; grWinh = height; - ratio = width/height; - fMouseRatioX = width / 640.0; fMouseRatioY = height / 480.0; @@ -467,7 +465,8 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen) m_sceneViewer->getCamera()->setName("Cam one"); m_sceneViewer->getCamera()->setViewport(new osg::Viewport(0, 0, grWinw, grWinh)); m_sceneViewer->getCamera()->setGraphicsContext(gw.get()); - m_sceneViewer->getCamera()->setProjectionMatrixAsPerspective(67.5, static_cast(ratio), 0.1, 12000.0); + m_sceneViewer->getCamera()->setProjectionMatrixAsPerspective(67.5f, static_cast(grWinw / grWinh), 0.2f, 9000.0f); + //m_sceneViewer->setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); m_sceneViewer->realize(); @@ -482,8 +481,8 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen) GfuiAddKey(screen, GFUIK_HOME, "Zoom Maximum", (void*)GR_ZOOM_MAX, grSetZoom, NULL); GfuiAddKey(screen, '*', "Zoom Default", (void*)GR_ZOOM_DFLT, grSetZoom, NULL);*/ - GfuiAddKey( 0, GFUIK_PAGEUP, "Select Previous Car", (void*)0, grPrevCar, NULL); - GfuiAddKey( 0, GFUIK_PAGEDOWN, "Select Next Car", (void*)0, grNextCar, NULL); + //GfuiAddKey( 0, GFUIK_PAGEUP, "Select Previous Car", (void*)0, grPrevCar, NULL); + //GfuiAddKey( 0, GFUIK_PAGEDOWN, "Select Next Car", (void*)0, grNextCar, NULL); /*GfuiAddKey(screen, GFUIK_F2, "Driver Views", (void*)0, grSelectCamera, NULL); GfuiAddKey(screen, GFUIK_F3, "Car Views", (void*)1, grSelectCamera, NULL); @@ -527,18 +526,18 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen) int refresh(tSituation *s) { - //int i; - int nb = s->_ncars; - tCarElt *car = s->cars[nb-1]; + //int i; + int nb = s->_ncars; + tCarElt *car = s->cars[nb-1]; osg::Vec3 eye, center, up, speed, P, p; float offset = 0; int Speed = 0; - p[0] = car->_pos_X+ car->_drvPos_x; - p[1] = car->_pos_Y+car->_drvPos_y; - p[2] = car->_pos_Z+car->_drvPos_z; - // osgXformPnt3(p, car->_posMat); + p[0] = car->_pos_X + car->_drvPos_x; + p[1] = car->_pos_Y + car->_drvPos_y; + p[2] = car->_pos_Z + car->_drvPos_z; + osgXformPnt3(p, car->_posMat); eye[0] = p[0]; eye[1] = p[1]; @@ -551,10 +550,10 @@ refresh(tSituation *s) fovy = spanfovy; }*/ - P[0] = (car->_pos_X + 30.0 * cos(car->_glance + offset+car->_yaw)); - P[1] = (car->_pos_Y + 30.0 * sin(car->_glance + offset+car->_yaw)); - P[2] = car->_pos_Z+car->_yaw; - //osgXformPnt3(P, car->_posMat); + P[0] = (car->_pos_X + 30.0 * cos(car->_glance + offset + car->_yaw)); + P[1] = (car->_pos_Y + 30.0 * sin(car->_glance + offset + car->_yaw)); + P[2] = car->_pos_Z + car->_yaw; + osgXformPnt3(P, car->_posMat); center[0] = P[0]; center[1] = P[1]; @@ -572,9 +571,7 @@ refresh(tSituation *s) osg::Camera * camera = m_sceneViewer->getCamera(); camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - //camera->setProjectionMatrixAsPerspective(67.5, ratio, 1, 12000.0); - camera->setViewMatrixAsLookAt( eye, center, osg::Vec3(0,0,1)); - + camera->setViewMatrixAsLookAt( eye, center, up); cars.updateCars(); @@ -807,9 +804,11 @@ initTrack(tTrack *track) return grLoadScene(track); } -int initCars(tSituation *s){ +int initCars(tSituation *s) +{ m_sceneroot->addChild(cars.loadCars(s)); GfOut("All cars loaded\n"); + return 0; } diff --git a/src/modules/graphic/osggraph/OsgMath.h b/src/modules/graphic/osggraph/OsgMath.h index bf6d85782..325a40ef4 100644 --- a/src/modules/graphic/osggraph/OsgMath.h +++ b/src/modules/graphic/osggraph/OsgMath.h @@ -34,15 +34,5 @@ extern void osgXformPnt3( osg::Vec3 dst, const osg::Vec3 src, const osgMat4 mat inline void osgXformPnt3( osg::Vec3 dst, const osgMat4 mat ) { osgXformPnt3 ( dst, dst, mat ); } -void osgXformPnt3(osg::Vec3 dst, const osg::Vec3 src, const osgMat4 mat); -/*{ - float t0 = src[0]; - float t1 = src[1]; - float t2 = src[2]; - - dst[0] = t0*mat[0][0] + t1*mat[1][0] + t2*mat[2][0] + mat[3][0]; - dst[1] = t0*mat[0][1] + t1*mat[1][1] + t2*mat[2][1] + mat[3][1]; - dst[2] = t0*mat[0][2] + t1*mat[1][2] + t2*mat[2][2] + mat[3][2]; -}*/ #endif /* _OSGMATH_H_ */ diff --git a/src/modules/graphic/osggraph/OsgScene.cpp b/src/modules/graphic/osggraph/OsgScene.cpp index 6128dbdbd..3a96d2982 100644 --- a/src/modules/graphic/osggraph/OsgScene.cpp +++ b/src/modules/graphic/osggraph/OsgScene.cpp @@ -261,7 +261,7 @@ bool LoadTrack(std::string strTrack) osgLoader loader; GfOut("Chemin Textures : %s\n", m_strTexturePath.c_str()); loader.AddSearchPath(m_strTexturePath); - osg::Node *pTrack = loader.Load3dFile(strTrack); + osg::Node *pTrack = loader.Load3dFile(strTrack, false); //osgDB::writeNodeFile(*pTrack,"mytrack.osg"); @@ -301,7 +301,7 @@ bool LoadBackground(std::string strTrack) osgLoader loader; GfOut("Chemin Textures : %s\n", m_strTexturePath.c_str()); loader.AddSearchPath(m_strTexturePath); - osg::Node *m_background = loader.Load3dFile(strTrack); + osg::Node *m_background = loader.Load3dFile(strTrack, false); if (m_background) {