static boost::python::list get_abc_angle_axis() { const RenderedBuffer & renderedBuffer = BridgeParameter::instance().first_noaccessory_buffer(); D3DXMATRIX convertMat( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1); D3DXMATRIX convertedWordInv; ::D3DXMatrixMultiply(&convertedWordInv, &renderedBuffer.world_inv, &convertMat); D3DXVECTOR3 eye; { D3DXVECTOR3 v; UMGetCameraEye(&v); d3d_vector3_transform(eye, v, convertedWordInv); } D3DXVECTOR3 at; { D3DXVECTOR3 v; UMGetCameraAt(&v); d3d_vector3_transform(at, v, convertedWordInv); } D3DXVECTOR3 up; { D3DXVECTOR3 v; UMGetCameraUp(&v); d3d_vector3_dir_transform(up, v, convertedWordInv); ::D3DXVec3Normalize(&up, &up); } Imath::V3d trans((double)eye.x, (double)eye.y, (double)(eye.z)); D3DXMATRIX view; ::D3DXMatrixLookAtLH(&view, &eye, &at, &up); Imath::M44d rot( -view.m[0][0], view.m[0][1], view.m[0][2], 0, -view.m[1][0], view.m[1][1], view.m[1][2], 0, view.m[2][0], -view.m[2][1], -view.m[2][2], 0, 0, 0, 0, 1); Imath::Quatd quat = Imath::extractQuat(rot); quat.normalize(); boost::python::list result; result.append(quat.angle()); result.append(quat.axis()[0]); result.append(quat.axis()[1]); result.append(quat.axis()[2]); return result; }
//-***************************************************************************** Abc::V3d XformSample::getAxis() const { Imath::Quatd q = Imath::extractQuat( this->getMatrix() ); return q.axis(); }
static void export_alembic_camera(AlembicArchive &archive, const RenderedBuffer & renderedBuffer, bool isUseEuler) { static const int cameraKey = 0xFFFFFF; Alembic::AbcGeom::OObject topObj(*archive.archive, Alembic::AbcGeom::kTop); Alembic::AbcGeom::OXform xform; if (archive.xform_map.find(cameraKey) != archive.xform_map.end()) { xform = archive.xform_map[cameraKey]; } else { xform = Alembic::AbcGeom::OXform(topObj, "camera_xform", archive.timesampling); archive.xform_map[cameraKey] = xform; Alembic::AbcGeom::OXformSchema &xformSchema = xform.getSchema(); archive.xform_schema_map[cameraKey] = xformSchema; } // set camera transform { Alembic::AbcGeom::OXformSchema &xformSchema = archive.xform_schema_map[cameraKey]; xformSchema.setTimeSampling(archive.timesampling); Alembic::AbcGeom::XformSample xformSample; D3DXMATRIX convertMat( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1); D3DXMATRIX convertedWordInv; ::D3DXMatrixMultiply(&convertedWordInv, &renderedBuffer.world_inv, &convertMat); D3DXVECTOR3 eye; { D3DXVECTOR3 v; UMGetCameraEye(&v); d3d_vector3_transform(eye, v,convertedWordInv); } D3DXVECTOR3 at; { D3DXVECTOR3 v; UMGetCameraAt(&v); d3d_vector3_transform(at, v, convertedWordInv); } D3DXVECTOR3 up; { D3DXVECTOR3 v; UMGetCameraUp(&v); d3d_vector3_dir_transform(up, v, convertedWordInv); ::D3DXVec3Normalize(&up, &up); } Imath::V3d trans((double)eye.x, (double)eye.y, (double)(eye.z)); xformSample.setTranslation(trans); D3DXMATRIX view; ::D3DXMatrixLookAtLH(&view, &eye, &at, &up); Imath::M44d rot( -view.m[0][0], view.m[0][1], view.m[0][2], 0, -view.m[1][0], view.m[1][1], view.m[1][2], 0, view.m[2][0], -view.m[2][1], -view.m[2][2], 0, 0, 0, 0, 1); Imath::Quatd quat = Imath::extractQuat(rot); quat.normalize(); if (isUseEuler) { Imath::V3d imeuler; quatToEuler(imeuler, quat); //UMMat44d umrot( // -view.m[0][0], view.m[0][1], view.m[0][2], 0, // -view.m[1][0], view.m[1][1], view.m[1][2], 0, // view.m[2][0], -view.m[2][1], -view.m[2][2], 0, // 0, 0, 0, 1); //UMVec3d umeuler = umbase::um_matrix_to_euler_xyz(umrot.transposed()); xformSample.setXRotation(umbase::um_to_degree(imeuler.y)); xformSample.setYRotation(umbase::um_to_degree(imeuler.x)); xformSample.setZRotation(-umbase::um_to_degree(imeuler.z)); } else { xformSample.setRotation(quat.axis(), umbase::um_to_degree(quat.angle())); } xformSchema.set(xformSample); } Alembic::AbcGeom::OCamera camera; if (archive.camera_map.find(cameraKey) != archive.camera_map.end()) { camera = archive.camera_map[cameraKey]; } else { camera = Alembic::AbcGeom::OCamera(xform, "camera", archive.timesampling); archive.camera_map[cameraKey] = camera; Alembic::AbcGeom::OCameraSchema &cameraSchema = camera.getSchema(); archive.camera_schema_map[cameraKey] = cameraSchema; } Alembic::AbcGeom::OCameraSchema &cameraSchema = archive.camera_schema_map[cameraKey]; cameraSchema.setTimeSampling(archive.timesampling); Alembic::AbcGeom::CameraSample sample; D3DXVECTOR4 v; UMGetCameraFovLH(&v); sample.setNearClippingPlane(v.z); sample.setFarClippingPlane(v.w); double fovy = v.x; double aspect = v.y; double fovx = 2.0 * atan(tan(fovy / 2.0)*(aspect)); double w = BridgeParameter::instance().frame_width / 10.0; double h = BridgeParameter::instance().frame_height / 10.0; double focalLength = w / (2.0 * tan(fovx / 2.0)); sample.setHorizontalAperture(w / 10.0); sample.setVerticalAperture(h / 10.0); sample.setFocalLength(focalLength); cameraSchema.set(sample); }