void FibreReader<DIM>::GetAllOrtho(std::vector< c_vector<double, DIM> >& first_direction, std::vector< c_vector<double, DIM> >& second_direction, std::vector< c_vector<double, DIM> >& third_direction) { assert(first_direction.empty()); assert(second_direction.empty()); assert(third_direction.empty()); if (mNumItemsPerLine != DIM*DIM) { EXCEPTION("Use GetAllAxi when reading axisymmetric fibres"); } for (unsigned i=0; i<mNumLinesOfData; i++) { c_matrix<double, DIM, DIM> temp_matrix; GetFibreSheetAndNormalMatrix(i, temp_matrix, true); //Note that although the matrix appears row-wise in the ascii .ortho file, //for convenience it is stored column-wise. matrix_column<c_matrix<double, DIM, DIM> > col0(temp_matrix, 0); first_direction.push_back(col0); if (DIM>=2) { matrix_column<c_matrix<double, DIM, DIM> > col1(temp_matrix, 1); second_direction.push_back(col1); } if (DIM==3) { matrix_column<c_matrix<double, DIM, DIM> > col2(temp_matrix, 2); third_direction.push_back(col2); } } }
TEST(PaletteTranslator, BuildSortLuminance) { //uint32 y = r * 299 + g * 587 + b * 114; Color col0(0, 0, 10); Color col1(0, 0, 11); Color col2(10, 0, 0); Color col3(11, 0, 0); Color col4(0, 10, 0); Color col5(0, 11, 0); Palette pal; pal.m_count = 6; pal[0] = col3; pal[1] = col5; pal[2] = col1; pal[3] = col2; pal[4] = col4; pal[5] = col0; Palette exp; exp.m_count = 6; exp[0] = col0; exp[1] = col1; exp[2] = col2; exp[3] = col3; exp[4] = col4; exp[5] = col5; PaletteTranslator pt; pt.BuildSortLuminance(pal, nullptr); ASSERT_TRUE( pal == exp ); }
//------------------------------------------------------------------------------- // @ IvRenderer::SetWorldMatrix() //------------------------------------------------------------------------------- // Sets the world matrix for the renderer //------------------------------------------------------------------------------- void IvRenderer::SetWorldMatrix(const IvMatrix44& matrix) { mWorldMat = matrix; mWVPMat = mProjectionMat*mViewMat*mWorldMat; IvMatrix33 worldMat3x3; IvVector3 col0(mWorldMat(0,0), mWorldMat(1,0), mWorldMat(2,0)); IvVector3 col1(mWorldMat(0,1), mWorldMat(1,1), mWorldMat(2,1)); IvVector3 col2(mWorldMat(0,2), mWorldMat(1,2), mWorldMat(2,2)); worldMat3x3.SetColumns(col0, col1, col2); mNormalMat.Rotation(Transpose(Inverse(worldMat3x3))); }
// extract frustum plane in world space. // the normals facing inward. // pass in view * projection matrix. void Frustum::InitFromMatrix(const Matrix &VP) { // near and far plane corners static float3 verts[8] = { // near plane corners float3( -1, -1,0 ), float3( 1, -1,0 ), float3( 1, 1,0 ), float3( -1, 1 ,0), // far plane corners. float3( -1, -1 ,1), float3( 1, -1,1 ), float3( 1, 1,1 ), float3( -1, 1,1 ) }; this->m_matrix = VP; float4 col0(VP(0,0), VP(1,0), VP(2,0), VP(3,0)); float4 col1(VP(0,1), VP(1,1), VP(2,1), VP(3,1)); float4 col2(VP(0,2), VP(1,2), VP(2,2), VP(3,2)); float4 col3(VP(0,3), VP(1,3), VP(2,3), VP(3,3)); // Planes face inward. m_planes[Near] = Plane(col2); // near m_planes[Far] = Plane(col3 - col2); // far m_planes[Left] = Plane(col3 + col0); // left m_planes[Right] = Plane(col3 - col0); // right m_planes[Top] = Plane(col3 - col1); // top m_planes[Bottom] = Plane(col3 + col1); // bottom // normalize all six planes for(int i = 0; i < 6; i++) { m_planes[i].Normalize(); } // tranform eight corner from device coordiate to world coordinate. Matrix invVP = VP; invVP.Invert(); for(int i = 0; i < 8; i++) { this->m_corners[i] = float3::Transform(verts[i],invVP); } }
//============================================================================== void DebugDrawer::drawGrid() { Vec4 col0(0.5, 0.5, 0.5, 1.0); Vec4 col1(0.0, 0.0, 1.0, 1.0); Vec4 col2(1.0, 0.0, 0.0, 1.0); const F32 SPACE = 1.0; // space between lines const U NUM = 57; // lines number. must be odd const F32 GRID_HALF_SIZE = ((NUM - 1) * SPACE / 2); setColor(col0); begin(GL_LINES); for(U x = - NUM / 2 * SPACE; x < NUM / 2 * SPACE; x += SPACE) { setColor(col0); // if the middle line then change color if(x == 0) { setColor(col1); } // line in z pushBackVertex(Vec3(x, 0.0, -GRID_HALF_SIZE)); pushBackVertex(Vec3(x, 0.0, GRID_HALF_SIZE)); // if middle line change col so you can highlight the x-axis if(x == 0) { setColor(col2); } // line in the x pushBackVertex(Vec3(-GRID_HALF_SIZE, 0.0, x)); pushBackVertex(Vec3(GRID_HALF_SIZE, 0.0, x)); } // render end(); }
void Camera::buildFrustumPlanes() { D3DXMATRIX VP = m_view * m_proj; D3DXVECTOR4 col0(VP(0, 0), VP(1, 0), VP(2, 0), VP(3, 0)); D3DXVECTOR4 col1(VP(0, 1), VP(1, 1), VP(2, 1), VP(3, 1)); D3DXVECTOR4 col2(VP(0, 2), VP(1, 2), VP(2, 2), VP(3, 2)); D3DXVECTOR4 col3(VP(0, 3), VP(1, 3), VP(2, 3), VP(3, 3)); // Planes face inward. mFrustumPlanes[0] = (D3DXPLANE)(col2); // near mFrustumPlanes[1] = (D3DXPLANE)(col3 - col2); // far mFrustumPlanes[2] = (D3DXPLANE)(col3 + col0); // left mFrustumPlanes[3] = (D3DXPLANE)(col3 - col0); // right mFrustumPlanes[4] = (D3DXPLANE)(col3 - col1); // top mFrustumPlanes[5] = (D3DXPLANE)(col3 + col1); // bottom for (int i = 0; i < 6; i++) D3DXPlaneNormalize(&mFrustumPlanes[i], &mFrustumPlanes[i]); }
TEST(PaletteTranslator, BuildDuplicatedColors) { Color col0(11, 12, 13); Color col1(14, 15, 16); Color col2(20, 21, 22, 0); Color col3(11, 12, 13); Color col4(30, 31, 32, 0); Palette pal; pal.m_count = 5; pal[0] = col0; pal[1] = col1; pal[2] = col2; pal[3] = col3; pal[4] = col4; Palette exp; exp.m_count = 3; exp[0] = col0; exp[1] = col1; exp[2] = col2; uint32 colCounts[256] = { 1, 10, 100, 1000, 10000 }; uint32 expectedColCounts[256] = { 1001, 10, 10100, 0, 0 }; PaletteTranslator pt; pt.BuildDuplicatedColors(pal, colCounts); ASSERT_TRUE( pal == exp ); ASSERT_TRUE( memcmp(colCounts, expectedColCounts, sizeof(colCounts)) == 0 ); uint8 pixels[] = { 0, 1, 2, 3, 4 }; const uint8 expectedPixels[] = { 0, 1, 2, 0, 2 }; pt.Translate(pixels, sizeof(pixels)); ASSERT_TRUE( memcmp(pixels, expectedPixels, sizeof(pixels)) == 0 ); }
// bilinear filtering void PointSampler::Sample(shading::Sample *samples, Cache &, bool mipmapping) const { for(int k = 0 + 0; k < 4; k++) { shading::Sample &s = samples[k]; Vec2q pos = ClampTexCoord <i32x4>(s.texCoord) * Vec2q(wMul, hMul); uint mip = 0; if(mipmapping) { floatq min = Min(s.texDiff.x * wMul, s.texDiff.y * hMul); uint pixels = uint(Minimize(min) * 0.6f); mip = 0; while(pixels) { mip++; pixels >>= 1; } mip = Min(mip, tex->Mips() - 1); } const u8 *data = (u8 *)tex->DataPointer(mip); int pitch = mipPitch[mip]; i32x4 x1(pos.x), y1(pos.y); i32x4 x2 = x1 + i32x4(1), y2 = y1 + i32x4(1); floatq dx = pos.x - floatq(x1), dy = pos.y - floatq(y1); //TODO: wylaczyc odbicie w pionie y1 = int(tex->Height()) - y1; y2 = int(tex->Height()) - y2; x1 >>= mip; y1 >>= mip; x2 >>= mip; y2 >>= mip; x1 &= i32x4(wMask >> mip); y1 &= i32x4(hMask >> mip); x2 &= i32x4(wMask >> mip); y2 &= i32x4(hMask >> mip); x1 = x1 + x1 + x1; x2 = x2 + x2 + x2; y1 *= pitch; y2 *= pitch; i32x4 o[4] = { x1 + y1, x2 + y1, x1 + y2, x2 + y2 }; #define DATA(a, b) *(u32*)&data[o[a][b]] // s.temp1 = Vec3q(B(0, 0), G(0, 0), R(0, 0)) * f32x4(1.0f / 255.0f); // continue; floatq red, green, blue; { // TODO upewnic sie ze mozna czytac zawsze 4 bajty i32x4 col0( DATA(0, 0), DATA(0, 1), DATA(0, 2), DATA(0, 3) ); i32x4 col1( DATA(1, 0), DATA(1, 1), DATA(1, 2), DATA(1, 3) ); i32x4 col2( DATA(2, 0), DATA(2, 1), DATA(2, 2), DATA(2, 3) ); i32x4 col3( DATA(3, 0), DATA(3, 1), DATA(3, 2), DATA(3, 3) ); floatq r[4], g[4], b[4]; r[0] = floatq( col0 & i32x4(255) ); g[0] = floatq( Shr<8>(col0) & i32x4(255) ); b[0] = floatq( Shr<16>(col0) & i32x4(255) ); r[1] = floatq( col1 & i32x4(255) ); g[1] = floatq( Shr<8>(col1) & i32x4(255) ); b[1] = floatq( Shr<16>(col1) & i32x4(255) ); r[2] = floatq( col2 & i32x4(255) ); g[2] = floatq( Shr<8>(col2) & i32x4(255) ); b[2] = floatq( Shr<16>(col2) & i32x4(255) ); r[3] = floatq( col3 & i32x4(255) ); g[3] = floatq( Shr<8>(col3) & i32x4(255) ); b[3] = floatq( Shr<16>(col3) & i32x4(255) ); red = Lerp(Lerp(r[0], r[1], dx), Lerp(r[2], r[3], dx), dy); green = Lerp(Lerp(g[0], g[1], dx), Lerp(g[2], g[3], dx), dy); blue = Lerp(Lerp(b[0], b[1], dx), Lerp(b[2], b[3], dx), dy); } #undef DATA s.temp1 = Vec3q(red, green, blue) * f32x4(1.0f / 255.0f); } }