void extractPlanes(){ GLfloat matrix[16], m[16], p[16]; glGetFloatv(GL_PROJECTION_MATRIX, p); glGetFloatv(GL_MODELVIEW_MATRIX, m); //Get the viewspace matrix glPushMatrix(); glLoadMatrixf(p); glMultMatrixf(m); glGetFloatv(GL_MODELVIEW_MATRIX, matrix); glPopMatrix(); getPlanes(matrix, planes); }
void reshape(int width, int height){ if(height == 0){ height = 1; } glViewport(0,0, (GLsizei)width, (GLsizei)height); double ratio = double(width)/double(height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, ratio, 10.0, 30.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ); getPlanes(); }
virtual bool load(const std::string& filename, Array &lat) { FREE_IMAGE_FORMAT type = FreeImage_GetFIFFromFilename(filename.c_str()); if(type == FIF_UNKNOWN) { AL_WARN("image format not recognized: %s", filename.c_str()); return false; } if(!FreeImage_FIFSupportsReading(type)) { AL_WARN("image format not supported: %s", filename.c_str()); return false; } destroy(); mImage = FreeImage_Load(type, filename.c_str(), 0); if (mImage == NULL) { AL_WARN("image failed to load: %s", filename.c_str()); return false; } FREE_IMAGE_COLOR_TYPE colorType = FreeImage_GetColorType(mImage); switch(colorType) { case FIC_MINISBLACK: case FIC_MINISWHITE: { FIBITMAP *res = FreeImage_ConvertToGreyscale(mImage); FreeImage_Unload(mImage); mImage = res; } break; case FIC_PALETTE: { if(FreeImage_IsTransparent(mImage)) { FIBITMAP *res = FreeImage_ConvertTo32Bits(mImage); FreeImage_Unload(mImage); mImage = res; } else { FIBITMAP *res = FreeImage_ConvertTo24Bits(mImage); FreeImage_Unload(mImage); mImage = res; } } break; case FIC_CMYK: { AL_WARN("CMYK images currently not supported"); return false; } break; default: break; } // flip vertical for OpenGL: //FreeImage_FlipVertical(mImage); //Freeimage is not tightly packed, so we use //a custom method instead of one of the Matrix //utility methods int planes = getPlanes(); AlloTy ty = getDataType(); int w, h; getDim(w, h); lat.format(planes, ty, w, h); Image::Format format = Image::getFormat(planes); switch(format) { case Image::LUMINANCE: { char *o_pix = (char *)(lat.data.ptr); int rowstride = lat.header.stride[1]; for(unsigned j = 0; j < lat.header.dim[1]; ++j) { char *pix = (char *)FreeImage_GetScanLine(mImage, j); memcpy(o_pix, pix, rowstride); o_pix += rowstride; } } break; case Image::RGB: { switch(lat.header.type) { case AlloUInt8Ty: { char *bp = (char *)(lat.data.ptr); int rowstride = lat.header.stride[1]; for(unsigned j = 0; j < lat.header.dim[1]; ++j) { RGBTRIPLE * pix = (RGBTRIPLE *)FreeImage_GetScanLine(mImage, j); Image::RGBPix<uint8_t> *o_pix = (Image::RGBPix<uint8_t> *)(bp + j*rowstride); for(unsigned i=0; i < lat.header.dim[0]; ++i) { o_pix->r = pix->rgbtRed; o_pix->g = pix->rgbtGreen; o_pix->b = pix->rgbtBlue; ++pix; ++o_pix; } } } break; case AlloFloat32Ty: { char *o_pix = (char *)(lat.data.ptr); int rowstride = lat.header.stride[1]; for(unsigned j = 0; j < lat.header.dim[1]; ++j) { char *pix = (char *)FreeImage_GetScanLine(mImage, j); memcpy(o_pix, pix, rowstride); o_pix += rowstride; } } break; default: break; } } break; case Image::RGBA: { switch(lat.header.type) { case AlloUInt8Ty: { char *bp = (char *)(lat.data.ptr); int rowstride = lat.header.stride[1]; for(unsigned j = 0; j < lat.header.dim[1]; ++j) { RGBQUAD *pix = (RGBQUAD *)FreeImage_GetScanLine(mImage, j); Image::RGBAPix<uint8_t> *o_pix = (Image::RGBAPix<uint8_t> *)(bp + j*rowstride); for(unsigned i=0; i < lat.header.dim[0]; ++i) { o_pix->r = pix->rgbRed; o_pix->g = pix->rgbGreen; o_pix->b = pix->rgbBlue; o_pix->a = pix->rgbReserved; ++pix; ++o_pix; } } } break; case AlloFloat32Ty: { char *o_pix = (char *)(lat.data.ptr); int rowstride = lat.header.stride[1]; for(unsigned j = 0; j < lat.header.dim[1]; ++j) { char *pix = (char *)FreeImage_GetScanLine(mImage, j); memcpy(o_pix, pix, rowstride); o_pix += rowstride; } } break; default: break; } } break; default: AL_WARN("image data not understood"); destroy(); return false; } return true; }
CC3Plane CC3Frustum::getNearPlane() { return getPlanes()[kCC3NearIdx]; }
CC3Plane CC3Frustum::getRightPlane() { return getPlanes()[kCC3RgtIdx]; }
CC3Plane CC3Frustum::getLeftPlane() { return getPlanes()[kCC3LeftIdx]; }
CC3Plane CC3Frustum::getBottomPlane() { return getPlanes()[kCC3BotmIdx]; }
CC3Plane CC3Frustum::getTopPlane() { return getPlanes()[kCC3TopIdx]; }