Changeset 3474

Show
Ignore:
Timestamp:
03/01/10 07:22:54 (5 months ago)
Author:
trichards
Message:

More work on ZODE and ZTerrain.

Location:
plugins/branches/0185_GEN_PHYSICS_REFACTOR_2
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZODE/src/HeightfieldResource.cpp

    r3463 r3474  
    2828#include <Zen/Core/Math/Math.hpp> 
    2929 
     30#include <boost/archive/binary_iarchive.hpp> 
     31 
    3032#include <boost/lexical_cast.hpp> 
     33#include <boost/cstdint.hpp> 
    3134 
    32 #include <stdio.h> 
    33 #include <stdlib.h> 
     35#include <vector> 
     36 
     37#include <fstream> 
     38#include <sstream> 
    3439 
    3540//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     
    7984    /// While we're reading the height data, we can get the 
    8085    /// height bounds of the heightmap as well. 
    81     /// (These may need to be scaled versions of the raw min/max  
     86    /// (These may need to be scaled versions of the raw min/max 
    8287    /// based on the scale config param). 
    83     const short *pBuffer; 
     88 
     89    std::vector<boost::int16_t> buffer(widthSamples * depthSamples); 
     90 
     91        boost::int16_t min = SHRT_MAX; 
     92        boost::int16_t max = SHRT_MIN; 
     93 
     94    std::ifstream stream(fileName, std::ios::in|std::ios::binary); 
     95 
     96    boost::archive::binary_iarchive inputArchive(stream, boost::archive::no_header | 
     97            boost::archive::no_tracking); 
     98 
     99    // Read the input stream if it exists 
     100    if(stream.good()) 
     101    { 
     102        for(int x = 0; x < widthSamples; x++) 
     103        { 
     104            for(int y = 0; y < depthSamples; y++) 
     105            { 
     106                boost::uint16_t c; 
     107                inputArchive & c; 
     108                buffer[x * widthSamples + y] = c; 
     109                max = max > c ? max : c; 
     110                min = min < c ? min : c; 
     111 
     112            } 
     113        } 
     114    } 
     115    else 
     116    { 
     117        std::stringstream errorMessage; 
     118        errorMessage << "Error opening " << fileName 
     119            << "file for input." << std::endl; 
     120        throw Zen::Utility::runtime_exception(errorMessage.str()); 
     121    } 
     122 
     123    const short *pBuffer = &buffer[0]; 
     124 
    84125    Math::Real minHeight; 
    85126    Math::Real maxHeight; 
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZODE/src/HeightfieldResource.hpp

    r3463 r3474  
    9191//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    9292 
    93 #endif ZEN_ZODE_HEIGHTFIELD_RESOURCE_HPP 
     93#endif // ZEN_ZODE_HEIGHTFIELD_RESOURCE_HPP 
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZTerrain/src/Terrain.cpp

    r3109 r3474  
    101101Terrain::loadPhysicsFromRaw(const std::string& _rawFileName, size_t _size, float _maxHeight, float _scaleXY, const Math::Matrix4& _transform, bool _bSerialize) 
    102102{ 
     103        Zen::Engine::Resource::I_ResourceService::config_type config; 
     104 
     105        config["fileName"] = _rawFileName; 
     106 
     107        m_pTerrainService->getPhysicsResourceService()->loadResource(config); 
     108 
    103109    Zen::Engine::World::I_Terrain::pPhysicsActor_type pActor = m_pTerrainService->getPhysicsZone()->createActor(); 
    104110    pActor->setCollisionShape(