From Marco Jez, improvement to the handling of coordinates frame in CubeMapGenerator.
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
#include <osgUtil/CubeMapGenerator>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <osg/Matrix>
|
||||
|
||||
using namespace osgUtil;
|
||||
|
||||
CubeMapGenerator::CubeMapGenerator(int texture_size)
|
||||
@@ -41,29 +43,28 @@ CubeMapGenerator::CubeMapGenerator(const CubeMapGenerator ©, const osg::Copy
|
||||
|
||||
void CubeMapGenerator::generateMap(bool use_osg_system)
|
||||
{
|
||||
const float duv = 2.0f/(texture_size_-1);
|
||||
osg::Matrix M;
|
||||
|
||||
if (use_osg_system) {
|
||||
M = osg::Matrix::rotate(osg::PI_2, osg::Vec3(1, 0, 0));
|
||||
} else {
|
||||
M = osg::Matrix::identity();
|
||||
}
|
||||
|
||||
const float dst = 2.0f/(texture_size_-1);
|
||||
|
||||
float v = 1;
|
||||
float t = -1;
|
||||
for (int i=0; i<texture_size_; ++i) {
|
||||
float u = 1;
|
||||
for (int j=0; j<texture_size_; ++j) {
|
||||
if (use_osg_system) {
|
||||
set_pixel(0, j, i, compute_color(osg::Vec3(1, -u, v)));
|
||||
set_pixel(1, j, i, compute_color(osg::Vec3(-1, u, v)));
|
||||
set_pixel(2, j, i, compute_color(osg::Vec3(-u, v, 1)));
|
||||
set_pixel(3, j, i, compute_color(osg::Vec3(-u, -v, -1)));
|
||||
set_pixel(4, j, i, compute_color(osg::Vec3(-u, -1, v)));
|
||||
set_pixel(5, j, i, compute_color(osg::Vec3(u, 1, v)));
|
||||
} else {
|
||||
set_pixel(0, j, i, compute_color(osg::Vec3(1, v, -u)));
|
||||
set_pixel(1, j, i, compute_color(osg::Vec3(-1, v, u)));
|
||||
set_pixel(2, j, i, compute_color(osg::Vec3(-u, 1, v)));
|
||||
set_pixel(3, j, i, compute_color(osg::Vec3(-u, -1, -v)));
|
||||
set_pixel(4, j, i, compute_color(osg::Vec3(-u, v, -1)));
|
||||
set_pixel(5, j, i, compute_color(osg::Vec3(u, v, 1)));
|
||||
}
|
||||
u -= duv;
|
||||
float s = -1;
|
||||
for (int j=0; j<texture_size_; ++j) {
|
||||
set_pixel(0, j, i, compute_color(osg::Vec3(1, -t, -s) * M));
|
||||
set_pixel(1, j, i, compute_color(osg::Vec3(-1, -t, s) * M));
|
||||
set_pixel(2, j, i, compute_color(osg::Vec3(s, 1, t) * M));
|
||||
set_pixel(3, j, i, compute_color(osg::Vec3(s, -1, -t) * M));
|
||||
set_pixel(4, j, i, compute_color(osg::Vec3(s, -t, 1) * M));
|
||||
set_pixel(5, j, i, compute_color(osg::Vec3(-s, -t, -1) * M));
|
||||
s += dst;
|
||||
}
|
||||
v -= duv;
|
||||
t += dst;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user