void Vizzer::init(ApplicationData &app) { m_meshes.resize(20); //const FloatType radius, const ml::vec3<FloatType>& pos, const size_t stacks /*= 10*/, const size_t slices /*= 10*/, const ml::vec4<FloatType>& color for (int i = 0; i < 20; i++) { const vec3f pos = vec3f(util::randomUniform(-1.0f, 1.0f), util::randomUniform(-1.0f, 1.0f), util::randomUniform(-1.0f, 1.0f)); const vec4f color = vec4f(util::randomUniform(0.5f, 1.0f), util::randomUniform(0.5f, 1.0f), util::randomUniform(0.5f, 1.0f), 1.0f); m_meshes[i].load(app.graphics, TriMeshf(Shapesf::sphere(util::randomUniform(0.1f, 0.2f), pos, 10, 10, color))); } const string shaderDir = "../../frameworkD3D11/shaders/"; m_vsColor.load(app.graphics, shaderDir + "test.shader"); m_psColor.load(app.graphics, shaderDir + "test.shader"); m_constants.init(app.graphics); vec3f eye(1.0f, 1.0f, 4.5f); vec3f worldUp(0.0f, 0.0f, 1.0f); m_camera = Cameraf(-eye, worldUp, vec3f::origin, 60.0f, (float)app.window.getWidth() / app.window.getHeight(), 0.01f, 1000.0f, true); m_font.init(app.graphics, "Calibri"); m_world = mat4f::identity(); }
void SuperSolarSystemApp::BuildCubeFaceCamera( float x, float y, float z ) { // 以给定位置生成CubeMap XMFLOAT3 center( x, y, z ); XMFLOAT3 worldUp( 0.0f, 1.0f, 0.0f ); // 看向6个方向 XMFLOAT3 targets[6] = { XMFLOAT3( x + 1.0f, y, z ), // +X XMFLOAT3( x - 1.0f, y, z ), // -X XMFLOAT3( x, y + 1.0f, z ), // +Y XMFLOAT3( x, y - 1.0f, z ), // -Y XMFLOAT3( x, y, z + 1.0f ), // +Z XMFLOAT3( x, y, z - 1.0f ) // -Z }; // 指定照相机的Up向量, 注意 +Y/-Y 不一样 XMFLOAT3 ups[6] = { XMFLOAT3( 0.0f, 1.0f, 0.0f ), // +X XMFLOAT3( 0.0f, 1.0f, 0.0f ), // -X XMFLOAT3( 0.0f, 0.0f, -1.0f ), // +Y XMFLOAT3( 0.0f, 0.0f, +1.0f ), // -Y XMFLOAT3( 0.0f, 1.0f, 0.0f ), // +Z XMFLOAT3( 0.0f, 1.0f, 0.0f ) // -Z }; for ( int i = 0; i < 6; ++i ) { mCubeMapCamera[i].LookAt( center, targets[i], ups[i] ); mCubeMapCamera[i].SetProj( 0.5f*XM_PI, 1.0f, 0.1f, 1000.0f ); mCubeMapCamera[i].UpdateView( ); } }
void RendererD3D::RotateWorldZAxis(double angle) { D3DXVECTOR3 worldUp( 0.0f, 0.0f, 1.0f ); // Rotate about world Z axis m_pStack->RotateAxis( &worldUp, (FLOAT) D3DXToRadian( angle ) ); }
void Billboard::LookAt(Vec3f ObjectPosition, Vec3f TargetPosition, Matrix4& matrix) // not quiet correct yet { Vec3f worldUp( 0.f, 0.f, 1.f); Vec3f i; Vec3f j; Vec3f k; k = TargetPosition - ObjectPosition; k.normalize(); i = worldUp.crossProductWith(k); i.normalize(); j = k.crossProductWith(i); // make matrix matrix.m_matrix[0] = i.x; matrix.m_matrix[1] = i.y; matrix.m_matrix[2] = i.z; matrix.m_matrix[3] = 0; matrix.m_matrix[4] = j.x; matrix.m_matrix[5] = j.y; matrix.m_matrix[6] = j.z; matrix.m_matrix[7] = 0; matrix.m_matrix[8] = k.x; matrix.m_matrix[9] = k.y; matrix.m_matrix[10] = k.z; matrix.m_matrix[11] = 0; matrix.m_matrix[12] = 0.0f; matrix.m_matrix[13] = 0.0f; matrix.m_matrix[14] = 0.0f; matrix.m_matrix[15] = 1; }
void Billboard::WorldAligned(Vec3f BillboardPosition, Vec3f CameraPosition, Matrix4& matrix) { Vec3f worldUp( 0.f, 0.f, 1.f ); Vec3f i; Vec3f j; Vec3f k; k = CameraPosition - BillboardPosition; k.normalize(); i = worldUp.crossProductWith(k); i.normalize(); j = k.crossProductWith(i); // make matrix matrix.m_matrix[0] = i.x; matrix.m_matrix[1] = i.y; matrix.m_matrix[2] = i.z; matrix.m_matrix[3] = 0; matrix.m_matrix[4] = j.x; matrix.m_matrix[5] = j.y; matrix.m_matrix[6] = j.z; matrix.m_matrix[7] = 0; matrix.m_matrix[8] = k.x; matrix.m_matrix[9] = k.y; matrix.m_matrix[10] = k.z; matrix.m_matrix[11] = 0; matrix.m_matrix[12] = BillboardPosition.x; matrix.m_matrix[13] = BillboardPosition.y; matrix.m_matrix[14] = BillboardPosition.z; matrix.m_matrix[15] = 1; }
void D3DPBRApp::BuildCubeFaceCamera(float x, float y, float z) { // Generate the cube map about the given position. XMFLOAT3 center(x, y, z); XMFLOAT3 worldUp(0.0f, 1.0f, 0.0f); // Look along each coordinate axis. XMFLOAT3 targets[6] = { XMFLOAT3(x+1.0f, y, z), // +X XMFLOAT3(x-1.0f, y, z), // -X XMFLOAT3(x, y+1.0f, z), // +Y XMFLOAT3(x, y-1.0f, z), // -Y XMFLOAT3(x, y, z+1.0f), // +Z XMFLOAT3(x, y, z-1.0f) // -Z }; // Use world up vector (0,1,0) for all directions except +Y/-Y. In these cases, we // are looking down +Y or -Y, so we need a different "up" vector. XMFLOAT3 ups[6] = { XMFLOAT3(0.0f, 1.0f, 0.0f), // +X XMFLOAT3(0.0f, 1.0f, 0.0f), // -X XMFLOAT3(0.0f, 0.0f, -1.0f), // +Y XMFLOAT3(0.0f, 0.0f, +1.0f), // -Y XMFLOAT3(0.0f, 1.0f, 0.0f), // +Z XMFLOAT3(0.0f, 1.0f, 0.0f) // -Z }; for(int i = 0; i < 6; ++i) { mCubeMapCamera[i].LookAt(center, targets[i], ups[i]); mCubeMapCamera[i].SetLens(0.5f*XM_PI, 1.0f, 0.1f, 1000.0f); mCubeMapCamera[i].UpdateViewMatrix(); } }
int Storm3D_ParticleSystem::QuadArray::lock(VXFORMAT_PART *pointer, int particleOffset, Storm3D_Scene *scene) { m_partOffset = particleOffset; pointer += particleOffset * 4; VXFORMAT_PART *vp = pointer; float frameWidth = 0.0f; float frameHeight = 0.0f; if(m_animInfo.numFrames > 1) { frameWidth = 1.0f / m_animInfo.textureUSubDivs; frameHeight = 1.0f / m_animInfo.textureVSubDivs; } BYTE *verts = (BYTE*)&vp[0].position; BYTE *uvs = (BYTE*)&vp[0].texcoords; BYTE *colors = (BYTE*)&vp[0].color; DWORD stride = sizeof(VXFORMAT_PART); D3DXMATRIX mv = scene->camera.GetViewMatrix(); DWORD c0 = 0; // Up rotation MAT view(scene->camera.GetViewMatrix()); VC3 worldUp(0, 1.f, 0); view.RotateVector(worldUp); QUAT q; rotateToward(worldUp, VC3(0, 0, 1.f), q); MAT g; g.CreateRotationMatrix(q); for(int i = 0; i < m_numParts; i++) { Storm3D_PointParticle& p = m_parts[i]; float sa = sinf(p.angle); float ca = cosf(p.angle); float hsize = 0.5f*p.size; float x1,y1,x2,y2,x3,y3,x4,y4; quad_util::rotatePointFast(x1, y1, -hsize, hsize, ca, sa); quad_util::rotatePointFast(x2, y2, hsize, hsize, ca, sa); quad_util::rotatePointFast(x3, y3, -hsize, -hsize, ca, sa); quad_util::rotatePointFast(x4, y4, hsize, -hsize, ca, sa); VC3 v; v.x = p.position.x * mv.m[0][0] + p.position.y * mv.m[1][0] + p.position.z * mv.m[2][0] + mv.m[3][0]; v.y = p.position.x * mv.m[0][1] + p.position.y * mv.m[1][1] + p.position.z * mv.m[2][1] + mv.m[3][1]; v.z = p.position.x * mv.m[0][2] + p.position.y * mv.m[1][2] + p.position.z * mv.m[2][2] + mv.m[3][2]; VC3 v1(x1, y1, 0); VC3 v2(x2, y2, 0); VC3 v3(x3, y3, 0); VC3 v4(x4, y4, 0); if(faceUp) { g.RotateVector(v1); g.RotateVector(v2); g.RotateVector(v3); g.RotateVector(v4); } v1 += v; v2 += v; v3 += v; v4 += v; /* VC3 v1(v.x + x1, v.y + y1, v.z); VC3 v2(v.x + x2, v.y + y2, v.z); VC3 v3(v.x + x3, v.y + y3, v.z); VC3 v4(v.x + x4, v.y + y4, v.z); { v1 -= v; g.RotateVector(v1); v1 += v; v2 -= v; g.RotateVector(v2); v2 += v; v3 -= v; g.RotateVector(v3); v3 += v; v4 -= v; g.RotateVector(v4); v4 += v; } */ *((Vector*)verts) = v1; verts += stride; *((Vector*)verts) = v2; verts += stride; *((Vector*)verts) = v3; verts += stride; *((Vector*)verts) = v4; verts += stride; // Fill texturecoords if(m_animInfo.numFrames > 1) { int frame = (int)p.frame % m_animInfo.numFrames; int col = frame % m_animInfo.textureUSubDivs; int row = frame / m_animInfo.textureUSubDivs; float tx = frameWidth * (float)col; float ty = frameHeight * (float)row; *((float*)uvs) = tx; uvs += 4; *((float*)uvs) = ty; uvs += (stride - 4); *((float*)uvs) = tx + frameWidth; uvs += 4; *((float*)uvs) = ty; uvs += (stride - 4); *((float*)uvs) = tx; uvs += 4; *((float*)uvs) = ty + frameHeight; uvs += (stride - 4); *((float*)uvs) = tx + frameWidth; uvs += 4; *((float*)uvs) = ty + frameHeight; uvs += (stride - 4); } else { *((float*)uvs) = 0.0f; uvs += 4; *((float*)uvs) = 0.0f; uvs += (stride - 4); *((float*)uvs) = 1.0f; uvs += 4; *((float*)uvs) = 0.0f; uvs += (stride - 4); *((float*)uvs) = 0.0f; uvs += 4; *((float*)uvs) = 1.0f; uvs += (stride - 4); *((float*)uvs) = 1.0f; uvs += 4; *((float*)uvs) = 1.0f; uvs += (stride - 4); } c0 = (((DWORD)(p.alpha * 255.0f) &0xff) << 24) | (((DWORD)(factor.r * p.color.r * 255.0f) &0xff) << 16) | (((DWORD)(factor.g * p.color.g * 255.0f) &0xff) << 8) | (((DWORD)(factor.b * p.color.b * 255.0f) &0xff) ); *((DWORD*)colors) = c0; colors += stride; *((DWORD*)colors) = c0; colors += stride; *((DWORD*)colors) = c0; colors += stride; *((DWORD*)colors) = c0; colors += stride; } return m_numParts; }
void Vizzer::init(ApplicationData &app) { assets.init(app.graphics); vec3f eye(0.5f, 0.2f, 0.5f); vec3f worldUp(0.0f, 1.0f, 0.0f); camera = Cameraf(-eye, eye, worldUp, 60.0f, (float)app.window.getWidth() / app.window.getHeight(), 0.01f, 10000.0f); camera = Cameraf("-0.774448 1.24485 -1.35404 0.999848 1.80444e-009 -0.0174517 0.0152652 -0.484706 0.874544 -0.00845866 -0.874677 -0.484632 0 1 0 60 1.25 0.01 10000"); //-0.774448 1.24485 -1.35404 0.999848 1.80444e-009 -0.0174517 0.0152652 -0.484706 0.874544 -0.00845866 -0.874677 -0.484632 0 1 0 60 1.25 0.01 10000 font.init(app.graphics, "Calibri"); state.bundler.loadSensorFile(constants::dataDir + "/sensors/sample.sensor"); state.bundler.computeKeypoints(); state.bundler.addCorrespondences(1); state.bundler.addCorrespondences(2); state.bundler.addCorrespondences(4); state.bundler.addCorrespondences(6); state.bundler.addCorrespondences(12); state.bundler.addCorrespondences(20); state.bundler.addCorrespondences(30); state.bundler.addCorrespondences(40); state.bundler.addCorrespondences(60); state.bundler.addCorrespondences(80); state.bundler.addCorrespondences(100); state.bundler.solve(); state.bundler.thresholdCorrespondences(0.01); state.bundler.solve(); //state.bundler.thresholdCorrespondences(0.005); //state.bundler.solve(); state.bundler.saveKeypointCloud(constants::debugDir + "result.ply"); state.bundler.saveResidualDistribution(constants::debugDir + "residuals.csv"); state.frameCloudsSmall.resize(state.bundler.frames.size()); state.frameCloudsBig.resize(state.bundler.frames.size()); for (auto &frame : iterate(state.bundler.frames)) { vector<TriMeshf> meshesSmall, meshesBig; auto makeColoredBox = [](const vec3f ¢er, const vec4f &color, float radius) { TriMeshf result = ml::Shapesf::box(radius, radius, radius); result.transform(mat4f::translation(center)); result.setColor(color); return result; }; const int stride = 5; for (auto &p : frame.value.depthImage) { vec2i coord((int)p.x, (int)p.y); const vec3f framePos = frame.value.localPos(coord); if (!framePos.isValid() || p.x % stride != 0 || p.y % stride != 0) continue; meshesSmall.push_back(makeColoredBox(frame.value.frameToWorld * framePos, vec4f(frame.value.colorImage(coord)) / 255.0f, 0.002f)); meshesBig.push_back(makeColoredBox(frame.value.frameToWorld * framePos, vec4f(frame.value.colorImage(coord)) / 255.0f, 0.005f)); } state.frameCloudsSmall[frame.index] = D3D11TriMesh(app.graphics, Shapesf::unifyMeshes(meshesSmall)); state.frameCloudsBig[frame.index] = D3D11TriMesh(app.graphics, Shapesf::unifyMeshes(meshesBig)); } state.selectedCamera = 0; }