//=============================================================================// matrix transpose(const matrix& t1) { //first making the identity matrix int rows=t1.rows; int cols=t1.cols; matrix eye(cols,cols); for (int i=0 ; i<rows*rows; i++) { eye.array1d[i]=0; } for (int j=0; j<rows; j++) { eye.array1d[cols*j+j]=1; } int m=t1.rows,k=t1.cols,n=eye.cols; int lda=m,ldc=m,ldb=k; matrix product(m,n); double alpha=1,beta=0; //C<--alpha*A*B_beta*C dgemm("TSA","NSA",&m,&n,&k,&alpha,t1.array1d,&lda,eye.array1d,&ldb,&beta,product.array1d,&ldc); return product; }
TinyRenderObjectData::TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray<float>&depthBuffer, b3AlignedObjectArray<float>* shadowBuffer, b3AlignedObjectArray<int>* segmentationMaskBuffer, int objectIndex) :m_model(0), m_rgbColorBuffer(rgbColorBuffer), m_depthBuffer(depthBuffer), m_shadowBuffer(shadowBuffer), m_segmentationMaskBufferPtr(segmentationMaskBuffer), m_userData(0), m_userIndex(-1), m_objectIndex(objectIndex) { Vec3f eye(1,1,3); Vec3f center(0,0,0); Vec3f up(0,0,1); m_lightDirWorld.setValue(0,0,0); m_lightColor.setValue(1, 1, 1); m_localScaling.setValue(1,1,1); m_modelMatrix = Matrix::identity(); m_lightAmbientCoeff = 0.6; m_lightDiffuseCoeff = 0.35; m_lightSpecularCoeff = 0.05; }
bool getProjectionMatrix(Bottle b, Matrix &P) { double fx,fy,cx,cy; if(b.check("fx")) fx = b.find("fx").asDouble(); else return 0; if(b.check("fy")) fy = b.find("fy").asDouble(); else return 0; // we suppose that the center distorsion is already compensated if(b.check("w")) cx = b.find("w").asDouble()/2.0; else return 0; if(b.check("h")) cy = b.find("h").asDouble()/2.0; else return 0; double sth= 0.0; double sx = fx; double sy = fy; double ox = cx; double oy = cy; double f = 1.0; Matrix K = eye(3,3); K(0,0)=sx*f; K(1,1)=sy*f; K(0,1)=sth*f; K(0,2)=ox; K(1,2)=oy; Matrix Pi = zeros(3,4); Pi(0,0)=1.0; Pi(1,1)=1.0; Pi(2,2)=1.0; P = K*Pi; //fprintf(stderr, "Working with Projection %s\n", P.toString().c_str()); return 1; }
void hit_ball(float dirx, float diry, float dirz, float eyex, float eyey, float eyez, float hit_strength) { vec3 dir = glm::normalize(vec3(dirx, diry, dirz)); vec3 eye (eyex, eyey, eyez); for (int i = 0; i < numtableobjects; ++i) { vec3 pos = tableobjects[i].pos; GLfloat r = tableobjects[i].radius; GLfloat a = glm::dot(dir, dir); GLfloat b = 2.0f*glm::dot(dir, eye-pos); GLfloat c = glm::dot(eye-pos, eye-pos) - r*r; if (b*b-4.0f*a*c >= 0.0f) { // hit the ball GLfloat t = (-b - sqrtf(b*b-4.0f*a*c))/(2.0f*a); if (t > 0.0f) { // ensure ball is in front of person vec3 hit = eye + t*dir; vec3 hit_dir = glm::normalize(pos - hit); // update the object's rotation tableobjects[i].drot += hit_strength*glm::cross(dir, hit_dir)/(tableobjects[i].I); // balls can't move in the z direction hit_dir.z = 0.0f; dir.z = 0.0f; tableobjects[i].vel += hit_strength*glm::dot(dir, hit_dir)*hit_dir/tableobjects[i].mass; } } } }
Vector doubleTouchThread::locateContact(skinContact &sc) { Vector result(4,0.0); Matrix Twl = eye(4); iCubArm *lmb = new iCubArm("left"); iencsL->getEncoders(encsL->data()); Vector q(10,0.0); q.setSubvector(3,encsL->subVector(0,6)); // printf("encsL%s\n", q.toString().c_str()); lmb -> setAng(q*CTRL_DEG2RAD); Twl = lmb -> getH(cntctLinkNum+3, true); Vector posLink = cntctPosLink; posLink.push_back(1); result = Twl * posLink; result.pop_back(); delete lmb; return result; }
doubleTouchThread::doubleTouchThread(int _rate, const string &_name, const string &_robot, int _v, std::vector<SkinPart> _skinParts, double _jnt_vels, int _record, string _filename, string _color, bool _autoconnect, bool _dontgoback, const Vector &_hand_poss_master, const Vector &_hand_poss_slave) : PeriodicThread((double)_rate/1000.0), name(_name), robot(_robot),verbosity(_v), skinParts(_skinParts), record(_record), filename(_filename), color(_color), autoconnect(_autoconnect), jnt_vels(_jnt_vels), dontgoback(_dontgoback), handPossMaster(_hand_poss_master),handPossSlave(_hand_poss_slave) { step = 0; recFlag = 0; skinPort = new BufferedPort<iCub::skinDynLib::skinContactList>; outPort = new BufferedPort<Bottle>; armPossHome.resize(7,0.0); armPossHome[0]=-30.0*iCub::ctrl::CTRL_DEG2RAD; armPossHome[1]=30.0*iCub::ctrl::CTRL_DEG2RAD; armPossHome[3]=45.0*iCub::ctrl::CTRL_DEG2RAD; armL = new iCubArm("left"); armR = new iCubArm("right"); iter = 1; cntctPosLink.resize(3,0.0); cntctPosWRF.resize(3,0.0); cntctPosEE.resize(3,0.0); cntctNormDir.resize(3,0.0); cntctPressure = -1; cntctLinkNum = -1; cntctSkinPart = SKIN_PART_UNKNOWN; cntctH0 = eye(4); oldEEL.resize(3,0.0); oldEER.resize(3,0.0); slv=NULL; gue=NULL; sol=NULL; testLimb=NULL; }
int main() { printf("Hello, World\n"); vec3 const & test = glm::vec3(1.0,2.0,3.0); printf("Here is a vector: %f,%f,%f\n", test.x, test.y, test.z); vec3 eye(0,5,5); vec3 look(0); vec3 up(0,1,0); mat4 mvp = glm::lookAt(eye, look, up); printf("%.2f, %.2f, %.2f, %.2f\n", mvp[0][0], mvp[0][1], mvp[0][2], mvp[0][3]); printf("%.2f, %.2f, %.2f, %.2f\n", mvp[1][0], mvp[1][1], mvp[1][2], mvp[1][3]); printf("%.2f, %.2f, %.2f, %.2f\n", mvp[2][0], mvp[2][1], mvp[2][2], mvp[2][3]); printf("%.2f, %.2f, %.2f, %.2f\n", mvp[3][0], mvp[3][1], mvp[3][2], mvp[3][3]); return 0; }
void display( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); point4 eye( radius*sin(theta)*cos(phi), radius*sin(theta)*sin(phi), radius*cos(theta), 1.0 ); point4 at( 0.0, 0.0, 0.0, 1.0 ); vec4 up( 0.0, 1.0, 0.0, 0.0 ); mat4 mv = LookAt( eye, at, up ); glUniformMatrix4fv( model_view, 1, GL_TRUE, mv ); mat4 p = Perspective( fovy, aspect, zNear, zFar ); glUniformMatrix4fv( projection, 1, GL_TRUE, p ); glDrawArrays( GL_TRIANGLES, 0, NumVertices ); glutSwapBuffers(); }
int CBackStage1::Draw(){ //クリア Sun3D.Clear(color); //ビュー行列 D3DXVECTOR3 eye( x, y, z ); //視点 D3DXVECTOR3 at( x, ay, az ); //注視点 D3DXVECTOR3 up( 0, 1, 0 ); //上方向 D3DXMATRIX view; D3DXMatrixLookAtLH( &view, &eye, &at, &up ); Sun3D.SetTransform( D3DTS_VIEW, &view ); //フォグON Sun3D.SetRenderState(D3DRS_FOGCOLOR,color); Sun3D.SetRenderState(D3DRS_FOGENABLE,true); //床(3D) SunSprite3D sprite3D(&g_pStage1->imgYuki); RECT rect = {tho,0,tho+th,tw}; sprite3D.CreateRectZX( rect, -100 ); sprite3D.SetRepeat( th/ts, tw/ts ); sprite3D.Move( ( ((int)x-tw/2) / tw ) * tw, 0, 0 ); sprite3D.Draw(); sprite3D.Move( tw, 0, 0 ); // sprite3D.SetColor(alpha(127)); sprite3D.Draw(); //フォグOFF Sun3D.SetRenderState(D3DRS_FOGENABLE,false); //雲 Sun3D.SetBlendingType( BLEND_ADD ); g_pStage1->imgYuki.DrawClip( (-30*count) % 512, 0, alpha(50) ); g_pStage1->imgYuki.DrawClip( (-30*count) % 512 + 512, 0, alpha(50) ); g_pStage1->imgYuki.DrawClip( (-30*count) % 512 + 1024, 0, alpha(50) ); Sun3D.SetBlendingType( BLEND_NORMAL ); return 1; }
void CameraStereo::getFarClipCoordinates( Vec3f *topLeft, Vec3f *topRight, Vec3f *bottomLeft, Vec3f *bottomRight ) const { calcMatrices(); Vec3f viewDirection( mViewDirection ); viewDirection.normalize(); float ratio = mFarClip / mNearClip; Vec3f eye( getEyePointShifted() ); float shift = 0.5f * mEyeSeparation * (mNearClip / mConvergence); shift *= (mIsStereo ? (mIsLeft ? 1.0f : -1.0f) : 0.0f); float left = mFrustumLeft + shift; float right = mFrustumRight + shift; *topLeft = eye + (mFarClip * viewDirection) + (ratio * mFrustumTop * mV) + (ratio * left * mU); *topRight = eye + (mFarClip * viewDirection) + (ratio * mFrustumTop * mV) + (ratio * right * mU); *bottomLeft = eye + (mFarClip * viewDirection) + (ratio * mFrustumBottom * mV) + (ratio * left * mU); *bottomRight = eye + (mFarClip * viewDirection) + (ratio * mFrustumBottom * mV) + (ratio * right * mU); }
void DE_Mori_Tanaka_iso(phase_characteristics &phase, const int &n_matrix) { mat sumT = zeros(6,6); mat inv_sumT = zeros(6,6); std::shared_ptr<ellipsoid_multi> elli_multi; std::shared_ptr<ellipsoid> elli; //ptr on the matrix properties std::shared_ptr<state_variables_M> sv_0 = std::dynamic_pointer_cast<state_variables_M>(phase.sub_phases[n_matrix].sptr_sv_global); std::shared_ptr<state_variables_M> sv_eff = std::dynamic_pointer_cast<state_variables_M>(phase.sptr_sv_local); std::shared_ptr<state_variables_M> sv_r; //Compute the Eshelby tensor and the interaction tensor for each phase for(auto r : phase.sub_phases) { elli_multi = std::dynamic_pointer_cast<ellipsoid_multi>(r.sptr_multi); elli = std::dynamic_pointer_cast<ellipsoid>(r.sptr_shape); sv_r = std::dynamic_pointer_cast<state_variables_M>(r.sptr_sv_global); //Note The tangent modulus are turned in the coordinate system of the ellipspoid in the fillT function if (r.sptr_matprops->number == n_matrix) elli_multi->T = eye(6,6); else elli_multi->fillT_iso(sv_0->Lt, sv_r->Lt, *elli); //Compute the normalization interaction tensir sumT sumT += elli->concentration*elli_multi->T; } inv_sumT = inv(sumT); //Compute the strain concentration tensor A for(auto r : phase.sub_phases) { elli_multi = std::dynamic_pointer_cast<ellipsoid_multi>(r.sptr_multi); sv_r = std::dynamic_pointer_cast<state_variables_M>(r.sptr_sv_global); elli_multi->A = elli_multi->T*inv_sumT; sv_r->DEtot = elli_multi->A*sv_eff->DEtot; //Recall that the global coordinates of subphases is the local coordinates of the generic phase } }
int CBackStage3::Draw(){ D3DCOLOR color = xrgb(0,30,50); Sun3D.Clear( color ); //ビュー行列 D3DXVECTOR3 eye( x, y, z ); //視点 D3DXVECTOR3 at( x, ay, az ); //注視点 D3DXVECTOR3 up( 0, 1, 0 ); //上方向 D3DXMATRIX view; D3DXMatrixLookAtLH( &view, &eye, &at, &up ); Sun3D.SetTransform( D3DTS_VIEW, &view ); //フォグON Sun3D.SetRenderState(D3DRS_FOGCOLOR,color); Sun3D.SetRenderState(D3DRS_FOGENABLE,true); //床 SunSprite3D sprite3D(&imgYuki); RECT rect = {0,-512,512,512}; sprite3D.CreateRectZX( rect, -100 ); sprite3D.SetRepeat( 1, 1 ); sprite3D.Move( ( ((int)x-512/2) / 1024 ) * 1024, 0, 0 ); sprite3D.Draw(); sprite3D.Move( 1024, 0, 0 ); sprite3D.Draw(); //フォグOFF Sun3D.SetRenderState(D3DRS_FOGENABLE,false); //雲 Sun3D.SetBlendingType( BLEND_ADD ); imgYuki.DrawClip( (-10*count) % 512, 0, alpha(50) ); imgYuki.DrawClip( (-10*count) % 512 + 512, 0, alpha(50) ); imgYuki.DrawClip( (-10*count) % 512 + 1024, 0, alpha(50) ); Sun3D.SetBlendingType( BLEND_NORMAL ); return 1; }
bool getCamPrj(const ResourceFinder &rf, const string &type, Matrix **Prj) { ResourceFinder &_rf=const_cast<ResourceFinder&>(rf); *Prj=NULL; if (!_rf.isConfigured()) return false; string camerasFile=_rf.findFile("from").c_str(); if (!camerasFile.empty()) { Bottle parType=_rf.findGroup(type.c_str()); string warning="Intrinsic parameters for "+type+" group not found"; if (parType.check("cx") && parType.check("cy") && parType.check("fx") && parType.check("fy")) { double cx=parType.find("cx").asDouble(); double cy=parType.find("cy").asDouble(); double fx=parType.find("fx").asDouble(); double fy=parType.find("fy").asDouble(); Matrix K=eye(3,3); Matrix Pi=zeros(3,4); K(0,0)=fx; K(1,1)=fy; K(0,2)=cx; K(1,2)=cy; Pi(0,0)=Pi(1,1)=Pi(2,2)=1.0; *Prj=new Matrix; **Prj=K*Pi; return true; } else fprintf(stdout,"%s\n",warning.c_str()); } return false; }
void FullscreenPass::render_scene(Camera const& camera, RenderContext const& ctx) { if (!depth_stencil_state_) depth_stencil_state_ = ctx.render_device ->create_depth_stencil_state(false, false, scm::gl::COMPARISON_NEVER); if (!fullscreen_quad_) fullscreen_quad_ = scm::gl::quad_geometry_ptr(new scm::gl::quad_geometry( ctx.render_device, math::vec2(-1.f, -1.f), math::vec2(1.f, 1.f))); set_uniforms(pipeline_->get_current_scene(CameraMode::CENTER), ctx); for (int i(0); i < gbuffer_->get_eye_buffers().size(); ++i) { CameraMode eye(CameraMode::CENTER); if (gbuffer_->get_eye_buffers().size() > 1 && i == 0) eye = CameraMode::LEFT; if (gbuffer_->get_eye_buffers().size() > 1 && i == 1) eye = CameraMode::RIGHT; pre_rendering(camera, pipeline_->get_current_scene(eye), eye, ctx); FrameBufferObject* fbo(gbuffer_->get_eye_buffers()[i]); fbo->bind(ctx); ctx.render_context->set_viewport(scm::gl::viewport( math::vec2(0, 0), math::vec2(fbo->width(), fbo->height()))); ctx.render_context->set_depth_stencil_state(depth_stencil_state_); rendering(camera, pipeline_->get_current_scene(eye), eye, ctx); ctx.render_context->reset_state_objects(); fbo->unbind(ctx); post_rendering(camera, pipeline_->get_current_scene(eye), eye, ctx); } }
//----------------------------------------------------------------------------// void Direct3D10RenderTarget::updateMatrix() const { const float fov = 0.523598776f; const float w = d_area.getWidth(); const float h = d_area.getHeight(); const float aspect = w / h; const float midx = w * 0.5f; const float midy = h * 0.5f; d_viewDistance = midx / (aspect * 0.267949192431123f); D3DXVECTOR3 eye(midx, midy, -d_viewDistance); D3DXVECTOR3 at(midx, midy, 1); D3DXVECTOR3 up(0, -1, 0); D3DXMATRIX tmp; D3DXMatrixMultiply(&d_matrix, D3DXMatrixLookAtRH(&d_matrix, &eye, &at, &up), D3DXMatrixPerspectiveFovRH(&tmp, fov, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f)); d_matrixValid = false; }
int main(int argc, char *argv[]) { sdlvu.Init("SDLVU Basic Example", 50, 50, 512, 512); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); // camera setup Vec3f modelmin(-1,-1,-1), modelmax(1, 1, 1), eye(1, 2, 3), lookatcntr(0, 0, 0), up(0, 1, 0); float yfov = 45; float aspect = 1; float nearClip = 0.1f; // near plane distance relative to model diagonal length float farClip = 10.0f; // far plane distance (also relative) sdlvu.SetAllCams(modelmin, modelmax, eye, lookatcntr, up, yfov, aspect, nearClip, farClip); sdlvu.MainLoop(); return 0; }
//[[Rcpp::export]] mat one_pred_gp_gdp(mat X, vec y, mat param_row) { vec param = vectorise(param_row); double s2 = param[0]; double phi = param[1]; double tau = param[2]; vec d = param.tail(param.size()-3); int n = X.n_rows; mat XdX = xDx(X,d % d); mat K = tau * exp(-phi*XdX); mat Xt = X.t(); mat I = eye(n,n); mat S_i = (K.i() + I / s2).i(); vec mu = S_i*y / s2; vec pred_y = mvrnorm(mu,S_i); return reshape(pred_y,1,n); }
BOOL jcd3d::jcd3d_setViewTransform(LPDIRECT3DDEVICE9 lpd3dd, FLOAT eyeX, FLOAT eyeY, FLOAT eyeZ, FLOAT targetX, FLOAT targetY, FLOAT targetZ, FLOAT upX, FLOAT upY, FLOAT upZ) { if(lpd3dd == NULL) { return FALSE; } else { D3DXMATRIX out; D3DXVECTOR3 eye(eyeX, eyeY, eyeZ); D3DXVECTOR3 target(targetX, targetY, targetZ); D3DXVECTOR3 up(upX, upY, upZ); D3DXMatrixLookAtLH(&out, &eye, &target, &up); if(FAILED(lpd3dd->SetTransform(D3DTS_VIEW, &out))) { return FALSE; } else { return TRUE; } } }
void PerspectiveCamera::mousePressed(CameraScratch &scratch, QMouseEvent *event) { scratch.pickX = event->pos().x(); scratch.pickY = event->pos().y(); if (event->button() == Qt::LeftButton) { scratch.moveType = MoveType::ROTATING; } else if (event->button() == Qt::MidButton) { scratch.moveType = MoveType::PANNING; scratch.origEye = eye(); //Vector3 f = (lookat() - eye()).normalized(); //Vector3 s = Vector3::crossProduct(f, upDir()); scratch.origUp = upDir(); //origUp = Vector3::crossProduct(s, f); scratch.origLeft = leftDir(); } else if (event->button() == Qt::RightButton) { scratch.moveType = MoveType::TRUCKING; } else { scratch.moveType = MoveType::NOT_MOVING; } }
Matrix doubleTouchThread::findH0(skinContact &sc) { // Set the proper orientation for the touching end-effector Matrix H0(4,4); Vector x(3,0.0), z(3,0.0), y(3,0.0); x = sc.getNormalDir(); if (x[0] == 0.0) { x[0] = 0.00000001; // Avoid the division by 0 } if (curTaskType!="LHtoR" && curTaskType!="RHtoL") { z[0] = -x[2]/x[0]; z[2] = 1; y = -1*(cross(x,z)); } else { // When x[0]==+-1, We can exploit an easier rule: z[1] = x[2]; y = -1*(cross(x,z)); } // Let's make them unitary vectors: x = x / norm(x); y = y / norm(y); z = z / norm(z); H0 = eye(4); H0.setSubcol(x,0,0); H0.setSubcol(y,0,1); H0.setSubcol(z,0,2); H0.setSubcol(sc.getCoP(),0,3); return H0; }
void Viewer::initScene() { auto pScene = m_Settings.m_pRoot->FirstChildElement("Scene"); if(!pScene) { std::clog << "No Scene tag found in viewer settings file" << std::endl; return; } m_SceneDocumentFilePath = m_Path + pScene->Attribute("path"); if(tinyxml2::XML_NO_ERROR != m_SceneDocument.LoadFile(m_SceneDocumentFilePath.c_str())) { throw std::runtime_error("Unable to load scene file"); } pScene = m_SceneDocument.RootElement(); if(!pScene) { throw std::runtime_error("No root element in scene's XML file"); } auto path = m_SceneDocumentFilePath.directory(); m_pScene = makeUnique<Scene>(pScene, path, m_ShaderManager); m_ZNearFar.y = 2.f * length(m_pScene->getGeometry().getBBox().size()); getAttribute(*pScene, "far", m_ZNearFar.y); float nearFarRatio = pScene->FloatAttribute("nearFarRatio"); m_ZNearFar.x = m_ZNearFar.y * nearFarRatio; auto pCamera = m_Settings.m_pCacheRoot->FirstChildElement("ProjectiveCamera"); Vec3f eye(0), point(0, 0, -1), up(0, 1, 0); float fovY = radians(45.f); if(pCamera) { loadPerspectiveCamera(*pCamera, eye, point, up, fovY); } m_Camera = ProjectiveCamera(lookAt(eye, point, up), fovY, m_Settings.m_FramebufferSize.x, m_Settings.m_FramebufferSize.y, m_ZNearFar.x, m_ZNearFar.y); }
void Reservoir::normalize_to_echo() { double target = 1-m_EPSILON/2.; // we will try to reach this rho in the effective matrix double rho_estimation = 100.0; // initial rho estimation double h = m_DT/m_TAU; // convenience decay constant mat I = eye(m_N,m_N); // convenience identity matrix // first create a matrix of rho 1 based on // alpha beta and gammma parameters m_w = randomize(); m_w = normalize(m_w, 1.0); // evaluate the effective dynamical matrix mat e_w = h*rho_estimation*m_w + (1 - h)*I; // initial effective rho estimation double effective_rho_estimation = evaluate_rho(e_w); // we try to reach the leaky echo-state condition while ( not (( (1-m_EPSILON) < effective_rho_estimation) and (effective_rho_estimation<1.0)) ) { // evaluate the effective dynamical matrix e_w = h*rho_estimation*m_w + (1 - h)*I; // evaluate its spectral radius effective_rho_estimation = evaluate_rho(e_w); // update the real spectral radius based on // the amount of distance to the leaky-echo-state condition rho_estimation += (1.0/h)*(target-effective_rho_estimation); } // finally modify the weight matrix to the // converged spectral radius m_w = rho_estimation*m_G*m_w; }
void RenderingEngine::Render(float theta) const { const float distance = 10; const vec3 target(0, -0.15, 0); const vec3 up(0, 1, 0); vec3 eye(0, -0.15, distance * 2); mat4 view = mat4::LookAt(eye, target, up); glUseProgram(m_simple.Program); glUniformMatrix4fv(m_simple.Uniforms.Modelview, 1, 0, view.Pointer()); glDepthFunc(GL_ALWAYS); glBindTexture(GL_TEXTURE_2D, m_textures.Metal); RenderDrawable(m_quad, m_simple); eye = vec3(0, 0, distance); view = mat4::LookAt(eye, target, up); const mat4 model = mat4::RotateY(theta * 180.0f / 3.14f); const mat3 model3x3 = model.ToMat3(); const mat4 modelview = model * view; vec4 eyeWorldSpace(0, 0, -10, 1); vec4 eyeObjectSpace = model * eyeWorldSpace; glUseProgram(m_cubemap.Program); glUniform3fv(m_cubemap.Uniforms.EyePosition, 1, eyeObjectSpace.Pointer()); glUniformMatrix4fv(m_cubemap.Uniforms.Modelview, 1, 0, modelview.Pointer()); glUniformMatrix3fv(m_cubemap.Uniforms.Model, 1, 0, model3x3.Pointer()); glBindTexture(GL_TEXTURE_CUBE_MAP, m_textures.Cubemap); glEnableVertexAttribArray(m_cubemap.Attributes.Normal); glDepthFunc(GL_LESS); RenderDrawable(m_kleinBottle, m_cubemap); }
void Object3D::lookAt(const Vector3& target) { float* e = matrix.elements; Vector3 eye(e[3], e[7], e[11]); Vector3 z = eye - target; z.normalize(); Vector3 x = Vector3(0, 1, 0).cross(z); x.normalize(); Vector3 y = z.cross(x); e[0] = x.x * scale.x; e[4] = x.y * scale.x; e[8] = x.z * scale.x; e[1] = y.x * scale.y; e[5] = y.y * scale.y; e[9] = y.z * scale.y; e[ 2] = z.x * scale.z; e[ 6] = z.y * scale.z; e[10] = z.z * scale.z; matrixWorldNeedsUpdate = true; }
void MainWindow::_update_scene_matrix(const QMatrix4x4& mat) { QMatrix4x4 moo; QVector3D eye(sqrt(2.0)*_axis_len/2.0, 0, sqrt(2.0)*_axis_len/2.0); QVector3D center(0,0,0); QVector3D up(0,1,0); //moo.lookAt(eye,center,up); QVector4D xvec(_axis_len,0,0,1); QVector4D yvec(0,_axis_len,0,1); QVector4D zvec(0,0,_axis_len,1); xvec = moo*_mat*xvec; yvec = moo*_mat*yvec; zvec = moo*_mat*zvec; _xitem->setLine(0,0,xvec.x(),-xvec.y()); _yitem->setLine(0,0,yvec.x(),-yvec.y()); _zitem->setLine(0,0,zvec.x(),-zvec.y()); }
void drawPly(){ CPLYLoader ply; //读取Ply数据 ply.LoadModel("lizhenxiout-repaired.ply"); mygl.ClearColor(255,255,255); mygl.PenColor(255,0,0); mygl.ViewPort(0,0,640,480); mygl.MatrixMode(MY_PROJECTION); mygl.LoadIdentity(); mygl.Ortho(-1000,1000,-1000,1000,-1000,1000); mygl.MatrixMode(MY_MODELVIEW); mygl.LoadIdentity(); //mygl.RotateY(70); //mygl.Translate(500,0,500); //mygl.Scale(0.5,0.5,0.5); //设置材质 Point::ka = 0.15; Point::ks = 0.8; Point::kd = 0.15; //设置光照 Vector eye(1,1,0); Vector lightPos(1,1,1); //color(blue,green,red); Color lightColor = {0,255,0}; //mygl.setLight(eye,lightPos,lightColor,10,10,1); for(int i=0; i<ply.m_totalConnectedPoints*3; i+=3){ Point p(ply.mp_vertexXYZ[i],ply.mp_vertexXYZ[i+1],ply.mp_vertexXYZ[i+2]); mygl.DrawPexil(p); } mygl.bmp.SaveBmp("plyBmp.bmp"); }
void Object::draw(QPainter *painter, Matrix m, vector<double> canvsize){ for(std::vector< vector <int> >::iterator i = facets.begin(); i != facets.end(); ++i){ int a = (*i)[0]; int b = (*i)[1]; int c = (*i)[2]; Point n = (p[b] - p[a]) * (p[c] - p[a]); Point l(10000, 20000, 0000); l = m * l - p[a]; Point eye(0, 0, -100); eye = eye - p[a]; if (n.z() > 0) continue; QPointF polygon[i->size()]; int t = 0; for(std::vector <int>::iterator j = i->begin(); j != i->end(); ++j, ++t){ polygon[t] = QPointF(p[*j].x(), p[*j].y()); } painter->setPen(Qt::NoPen); painter->setBrush(_getcolor(n, l, eye)); painter->drawConvexPolygon(polygon, i->size()); } }
HRESULT RacorX4::FrameMove(FLOAT) { //D3DXMATRIX Ry; //D3DXMatrixRotationY(&Ry, 3.14f / 40.0f); //D3DXMatrixMultiply(&m_mtWorld, &m_mtWorld, &Ry); //m_spDevice->SetTransform(D3DTS_WORLD, &m_mtWorld); D3DXMatrixTranslation(&m_mtWorld, -m_vObjectCenter.x, -m_vObjectCenter.x, -m_vObjectCenter.x); D3DXMatrixMultiply(&m_mtWorld, &m_mtWorld, m_ArcBall.GetTranslationMatrix()); D3DXMatrixMultiply(&m_mtWorld, &m_mtWorld, m_ArcBall.GetRotationMatrix()); D3DXVECTOR3 pos(0.0f, 0.0f, 0.0f); D3DXVECTOR3 eye(0.0f, 0.0f, -3.7f * m_fObjectRadius + m_fZDist); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&m_mtView, &eye, &pos, &up); m_spDevice->SetVertexShaderConstant(CLIP_MATRIX, &(m_mtWorld*m_mtView*m_mtProj), 4); D3DXMATRIX inverseWorld; D3DXMatrixInverse(&inverseWorld, NULL, &m_mtWorld); m_spDevice->SetVertexShaderConstant(INVERSE_WORLD_MATRIX, inverseWorld, 3); m_spDevice->SetVertexShaderConstant(EYE_VECTOR, eye, 1); if (m_bKey['C']) { m_bKey['C'] = 0; ++m_dwCurrentColor; if (m_dwCurrentColor >= 3) m_dwCurrentColor = 0; } m_spDevice->SetVertexShaderConstant(SPEC_COLOR, m_vLightColor[m_dwCurrentColor],1); return S_OK; }
void OpenGL::resizeGL(int w, int h){ /* adjust clipping box */ QVector3D eye(1.5, 1.0, 1.0); QVector3D at(0.0, 0.0, 0.0); QVector3D up(0.0, 1.0, 0.0); QMatrix4x4 Projection, ModelView; Projection.setToIdentity(); ModelView.setToIdentity(); Projection.ortho(-2,2,-2,2,-4,4); ModelView.lookAt(eye,at,up); m_shaderProgram->setUniformValue("Projection", Projection); m_shaderProgram->setUniformValue("ModelView", ModelView); /* adjust viewport and clear */ /* if(w<h) glViewport(0,0,w,w); else glViewport(0,0,h,h); */ glViewport(0,0,w,h); /* set global size for use by drawing routine */ }
void Scene::Parse(std::string sceneFilename) { BeganParsing(); std::ifstream sceneFile(sceneFilename.c_str()); // Die if we couldn't find the file if (sceneFile.fail()) { printf("Scene::Parse - Could not find input scene file '%s'\n", sceneFilename.c_str()); exit(1); } //else // printf("All systems are go!\n"); //this->outputfilename = sceneFilename; //this->outputfilename char line[1024]; while (!sceneFile.eof()) { sceneFile.getline(line, 1023); std::stringstream ss; ss.str(line); std::string command; ss >> command; if (command == "Camera") { float ex, ey, ez, ux, uy, uz, lx, ly, lz, f, a; ss >> ex >> ey >> ez >> ux >> uy >> uz >> lx >> ly >> lz >> f >> a; STPoint3 eye(ex, ey, ez); STVector3 up(ux, uy, uz); STPoint3 lookAt(lx, ly, lz); ParsedCamera(eye, up, lookAt, f, a); } else if (command == "Output")