void Matrix::Transpone() { Matrix newMat(height,width); for(unsigned y = 0; y < height; ++y) { for(unsigned x = 0; x < width; ++x) { newMat.Mat[x][y] = Mat[y][x]; } } DeleteMatrix(); width = newMat.width; height = newMat.height; CreateMatrix(); for(unsigned y = 0; y < height; ++y) { for(unsigned x = 0; x < width; ++x) { Mat[y][x] = newMat.Mat[y][x]; } } }
void SpotLightBehavior::OnFrustumTest( IBehavior* pInvokingBehavior, IMessage* msg ) { SpotLightBehavior* lightBehaviorPtr = (SpotLightBehavior*)pInvokingBehavior; if( lightBehaviorPtr->lightPtr == 0 ) return; MessageT<FrustumHull*>* message = (MessageT<FrustumHull*>*)msg; Aabb tempAabb = lightBehaviorPtr->gameObject->GetAabb(); if( message->value->Collides( &tempAabb ) ) { //DebugRenderer::GetInstance()->DrawAabb( tempAabb ); const D3DXVECTOR3& attenuation = lightBehaviorPtr->lightPtr->GetAttenuation(); float adjacent = (-attenuation.y + sqrt( attenuation.y * attenuation.y - 4 * attenuation.z * (attenuation.x - 255.f))) / (2 * attenuation.z); float radAngle = acos(lightBehaviorPtr->lightPtr->GetCutOff()); float tanr = tan(radAngle); float opposite = tanr * adjacent; float4x4 newMat(lightBehaviorPtr->gameObject->GetWorldTransform()); newMat.XAxis *= opposite; newMat.YAxis *= opposite; newMat.ZAxis *= adjacent; *lightBehaviorPtr->lightPtr->GetWorldMatrixPtr() = *(D3DXMATRIX *)&newMat; RenderController::GetInstance()->AddVisibleLight(lightBehaviorPtr->lightPtr); } }
FgMatrixV operator*(T v) const { FgMatrixV<T> newMat(nrows,ncols); for (uint ii=0; ii<m_data.size(); ii++) newMat.m_data[ii] = m_data[ii] * v; return newMat; }
cv::Mat EMat::AppendRight(cv::Mat &src) { assert(src.rows == rows); cv::Mat newMat(rows, src.cols + cols, type()); AppendRight(src, newMat); *this = newMat; return newMat; }
cv::Mat EMat::AppendBottom(cv::Mat &src) { assert(src.cols == cols); cv::Mat newMat(src.rows + rows, cols, type()); AppendBottom(src, newMat); *this = newMat; return newMat; }
RGBImage GestureContext::drawSkeleton() { cv::Mat_<cv::Vec3b> newMat(480,640, cv::Vec3b(0,0,0)); Face *f = face(); cv::Scalar face_color(255,0,0); if (f) { cv::circle(newMat, f->center(), 9, face_color, 3); } return(RGBImage(newMat)); }
NS_IMETHODIMP nsThebesRenderingContext::SetTranslation(nscoord aX, nscoord aY) { PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetTranslation %d %d\n", this, aX, aY)); gfxMatrix newMat(mThebes->CurrentMatrix()); newMat.x0 = aX; newMat.y0 = aY; mThebes->SetMatrix(newMat); return NS_OK; }
FgMatrixV operator*(const FgMatrixV & m) const { FgMatrixV<T> newMat(nrows,m.ncols); FGASSERT(ncols == m.nrows); for (uint ii=0; ii<nrows; ii++) { for (uint jj=0; jj<m.ncols; jj++) { newMat.elem(ii,jj) = 0.0; for (uint kk=0; kk<ncols; kk++) newMat.elem(ii,jj) += this->elem(ii,kk) * m.elem(kk,jj); } } return newMat; }
void MapManager::createFromTexture( GLuint texture ) { GLint width, height, glFormat; int depth=0, channels=0, type; glBindTexture(GL_TEXTURE_2D, texture); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &glFormat); switch(glFormat) { case GL_RGB8: depth = CV_8U; channels = 3; break; case GL_RGBA8: depth = CV_8U; channels = 4; break; case GL_RGB16: depth = CV_16U; channels = 3; break; case GL_RGBA16: depth = CV_16U; channels = 4; break; default: qDebug() << "Unsupported texture format"; return; break; } type = (depth == CV_8U)? ((channels == 3)?CV_8UC3:CV_8UC4): ((channels == 3)?CV_16UC3:CV_16UC4); cv::Mat newMat(height, width, type); glGetTexImage(GL_TEXTURE_2D,0, (channels == 3)?GL_BGR_EXT:GL_BGRA_EXT, (depth == CV_8U)?GL_UNSIGNED_BYTE:GL_UNSIGNED_SHORT, newMat.data); m_fileName.clear(); resetHistory(); setMat(newMat); }
void PxSingleActor::applyWarp( const MatrixF& mat, bool interpRender, bool sweep ) { MatrixF newMat( mat ); if ( mActor ) { mWorld->releaseWriteLock(); mActor->wakeUp(); NxMat34 nxMat; nxMat.setRowMajor44( newMat ); { mActor->setAngularVelocity( NxVec3( 0.0f ) ); mActor->setLinearVelocity( NxVec3( 0.0f ) ); mActor->setGlobalOrientation( nxMat.M ); } /* if ( sweep ) { mResetPos = mat; sweepTest( &newMat ); } */ nxMat.setRowMajor44( newMat ); mActor->setGlobalPose( nxMat ); } Parent::setTransform( newMat ); mNextPos = newMat.getPosition(); mNextRot = newMat; if ( !interpRender ) { mLastPos = mNextPos; mLastRot = mNextRot; } }
void WaterPlane::setTransform( const MatrixF &mat ) { // We only accept the z value from the new transform. MatrixF newMat( true ); Point3F newPos = getPosition(); newPos.z = mat.getPosition().z; newMat.setPosition( newPos ); Parent::setTransform( newMat ); // Parent::setTransforms ends up setting our worldBox to something other than // global, so we have to set it back... but we can't actually call setGlobalBounds // again because it does extra work adding and removing us from the container. mGlobalBounds = true; mObjBox.minExtents.set(-1e10, -1e10, -1e10); mObjBox.maxExtents.set( 1e10, 1e10, 1e10); // Keep mWaterPlane up to date. mWaterFogData.plane.set( 0, 0, 1, -getPosition().z ); }
void Parser::parsefile(std::ifstream &inputfile, Camera *cam, RayTracer *tracer, int* maxD){ // this sets the default BRDF // whenever a primitive is created // this is used for its material // the defaults as in OpenGL are //ka ambient = Color(0.2,0.2,0.2); //kd diffuse = Color(0.8,0.8,0.8); //ks specular = Color(0.0,0.0,0.0); //ke emission = Color(0.0,0.0,0.0); //kr reflection = Color(0.0,0.0,0.0); //s shininess = 0.0; BRDF tempBRDF; std::vector<glm::dmat4> transforms; transforms.clear(); glm::dmat4 identity, currMatrix, tempMat, helper,helper2,mvt; identity = glm::dmat4(1.0); currMatrix= glm::dmat4(1.0); tempMat= glm::dmat4(1.0); helper= glm::dmat4(1.0); helper2= glm::dmat4(1.0); mvt= glm::dmat4(1.0); glm::dvec3 tempVec; std::string line; char command[MAX_CHARS]; unsigned int commentNumber = 0; while (!inputfile.eof()) { getline(inputfile, line); if (inputfile.eof()) { break; } if (line[0]=='#') { //std::cout << "Comment # is: " << commentNumber << std::endl; //std::cout << "Comment: " << line << std::endl; commentNumber++; continue; //comment lines } int num = sscanf (line.c_str(), "%s", command); if (num != 1) { continue; // Blank lines; } // Now, we simply parse the file by looking at the first line for the various commands /************** CAMERA LOCATION **********/ if (!strcmp(command, "camera")) { double lookfrom[3], lookat[3], up[3], fov ; glm::dvec3 lookfrom0,lookat0,up0; int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", command, lookfrom, lookfrom+1, lookfrom+2, lookat, lookat+1, lookat+2, up, up+1, up+2, &fov) ; if (num != 11) { fprintf(stderr, "camera from[3] at[3] up[3] fov\n") ; exit(1) ; } assert(!strcmp(command,"camera")) ; // Set up modelview and projection matrices per camera parameters lookfrom0.x=lookfrom[0]; lookfrom0.y=lookfrom[1]; lookfrom0.z=lookfrom[2]; lookat0.x=lookat[0]; lookat0.y=lookat[1]; lookat0.z=lookat[2]; up0.x=up[0]; up0.y=up[1]; up0.z=up[2]; cam->SetCamera(lookfrom0,lookat0,up0,fov); } /****************************************/ /*********** GEOMETRY *******************/ else if (!strcmp(command, "model")) { char fileName[MAX_CHARS]; char ccwVerts[MAX_CHARS]; ccwVerts[0] = 0; fileName[0] =0; bool ccw = true; int num = sscanf(line.c_str(), "%s %s %s", command, fileName, ccwVerts); if(num != 3) { fprintf(stderr, "model filename ccw\n"); exit(1); } fprintf(stdout,"ccwVerts: %s \n",ccwVerts); if (strcmp(ccwVerts, "ccw") == 0){ std::cout << "counter clockwise vertices " << std::endl; ccw = true; } else if (strcmp(ccwVerts, "cw") == 0){ std::cout << "clockwise vertices " << std::endl; ccw = false; } printMatrix(currMatrix); tracer->AddPrimitive(new Model(fileName,Material(tempBRDF),currMatrix,ccw)); } else if (!strcmp(command, "sphere")) { double radius ; // Syntax is sphere x y z radius double pos[3] ; int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf", command, pos, pos+1, pos+2, &radius); if (num != 5) { fprintf(stderr, "sphere x y z radius\n") ; exit(1) ; } tempVec = glm::dvec3(pos[0],pos[1],pos[2]); //std::cout << "tempMat before" << std::endl; //printMatrix(tempMat); //std::cout << "inverse of currMatrix" << std::endl; tempMat = glm::inverse(currMatrix); //printMatrix(tempMat); //std::cout << "inversetranspose of currMatrix" << std::endl; mvt = glm::inverseTranspose(currMatrix); //printMatrix(mvt); tracer->AddPrimitive(new Sphere(tempVec, radius, Material(tempBRDF), tempMat, currMatrix, mvt));// makes a sphere with material props from the template BRDF } else if (!strcmp(command, "maxverts")) { int num = sscanf(line.c_str(), "%s %d", command, &maxverts) ; assert(num == 2) ; assert(maxverts > 0) ; assert(!strcmp(command,"maxverts")) ; assert(vert = new Vertex[maxverts]) ; } else if (!strcmp(command, "maxvertnorms")) { int num = sscanf(line.c_str(), "%s %d", command, &maxvertnorms) ; assert(num == 2) ; assert(maxvertnorms > 0) ; assert(!strcmp(command,"maxvertnorms")) ; assert(vertnorm = new VertexNormal[maxvertnorms]) ; } else if (!strcmp(command, "vertex")) { // Add a vertex to the stack assert(maxverts) ; assert(curvert < maxverts) ; Vertex v ; int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, v.pos, v.pos+1, v.pos+2) ; assert(num == 4) ; assert(!strcmp(command,"vertex")) ; vert[curvert] = v ; ++curvert ; } else if (!strcmp(command, "vertexnormal")) { // Add a vertex to the stack with a normal assert(maxvertnorms) ; assert(curvertnorm < maxvertnorms) ; VertexNormal vn ; int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf %lf %lf", command, vn.pos, vn.pos+1, vn.pos+2, vn.normal, vn.normal+1, vn.normal+2) ; assert(num == 7) ; assert(!strcmp(command,"vertexnormal")) ; vertnorm[curvertnorm] = vn ; ++curvertnorm ; } else if (!strcmp(command, "tri")) { // Triangle from 3 vertices int pts[3] ; int num = sscanf(line.c_str(), "%s %d %d %d", command, pts, pts+1, pts+2) ; assert(num == 4) ; assert(!strcmp(command,"tri")) ; int i,j ; for (i = 0 ; i < 3 ; i++) { assert(pts[i] >= 0 && pts[i] < maxverts) ; } double vertex[3][3] ; double normal[3] ; for (i = 0 ; i < 3 ; i++) for (j = 0 ; j < 3 ; j++) vertex[i][j] = vert[pts[i]].pos[j] ; // Calculate the face normal double vec1[3], vec2[3], vect3[3] ; for (i = 0 ; i < 3 ; i++) { vec1[i] = vertex[1][i] - vertex[0][i] ; vec2[i] = vertex[2][i] - vertex[0][i] ; } vect3[0] = vec1[1]*vec2[2] - vec1[2]*vec2[1] ; vect3[1] = vec1[2]*vec2[0] - vec1[0]*vec2[2] ; vect3[2] = vec1[0]*vec2[1] - vec1[1]*vec2[0] ; double norm = 0 ; for (i = 0 ; i < 3 ; i++) norm += vect3[i] * vect3[i] ; norm = sqrt(norm) ; if (norm == 0) {normal[0] = 0 ; normal[1] = 0 ; normal[2] = 1.0 ;} else { for (i = 0 ; i < 3 ; i++) normal[i] = vect3[i] / norm ; } //starts glm::dvec3 verts[3], temps[3]; glm::dvec4 tempnormie; for(i = 0; i < 3; i++){ verts[i] = glm::dvec3(vertex[i][0], vertex[i][1], vertex[i][2]); glm::dvec4 temp = currMatrix*glm::dvec4(verts[i],1); temps[i] = temp.xyz(); } glm::dvec3 normie(normal[0], normal[1], normal[2]); tempMat = glm::inverse(currMatrix); tempMat = glm::transpose(tempMat); tempnormie=tempMat*glm::dvec4(normie,0); tempnormie = glm::normalize(tempnormie); glm::dvec3 tempNormie(tempnormie); // makes a triangle with material props from the tempBRDF std::cout<<glm::to_string(tempNormie)<<std::endl; tracer->AddPrimitive(new Triangle (temps, tempNormie, Material(tempBRDF))); } else if (!strcmp(command, "trinormal")) { int pts[3] ; int num = sscanf(line.c_str(), "%s %d %d %d", command, pts, pts+1, pts+2) ; assert(num == 4) ; assert(!strcmp(command,"trinormal")) ; int i; for (i = 0 ; i < 3 ; i++) { assert(pts[i] >= 0 && pts[i] < maxvertnorms) ; } printf("trinormal\n"); glm::dvec3 verts[3]; glm::dvec3 normie[3]; for(int i = 0; i < 3; i++){ verts[i] = glm::dvec3(vertnorm[pts[i]].pos[0], vertnorm[pts[i]].pos[1], vertnorm[pts[i]].pos[2]); normie[i] = glm::dvec3(vertnorm[pts[i]].normal[0], vertnorm[pts[i]].normal[1], vertnorm[pts[i]].normal[2]); } double normal[3] ; double vec1[3], vec2[3], vect3[3] ; for (i = 0 ; i < 3 ; i++) { vec1[i] = vertnorm[1].pos[i] - vertnorm[0].pos[i] ; vec2[i] = vertnorm[2].pos[i] - vertnorm[0].pos[i] ; } vect3[0] = vec1[1]*vec2[2] - vec1[2]*vec2[1] ; vect3[1] = vec1[2]*vec2[0] - vec1[0]*vec2[2] ; vect3[2] = vec1[0]*vec2[1] - vec1[1]*vec2[0] ; double norm = 0 ; for (i = 0 ; i < 3 ; i++) norm += vect3[i] * vect3[i] ; norm = sqrt(norm) ; if (norm == 0) {normal[0] = 0 ; normal[1] = 0 ; normal[2] = 1.0 ; } else { for (i = 0 ; i < 3 ; i++) normal[i] = vect3[i] / norm ; } Triangle* triangle = new Triangle(verts, normie, Material(tempBRDF));// makes a triangle with material props from the tempBRDF triangle->setFaceNormal(glm::dvec3 (normal[0], normal[1], normal[2])); tracer->AddPrimitive(triangle); } /******************************************/ /**************** TRANSFORMATIONS *********/ else if (!strcmp(command, "translate")) { double x,y,z ; // Translate by x y z as in standard OpenGL int num = sscanf(line.c_str(), "%s %lf %lf %lf",command, &x, &y, &z) ; if (num != 4) { fprintf(stderr, "translate x y z\n") ; exit(1) ; } helper2 = currMatrix; currMatrix = helper2 * glm::translate(glm::dmat4(1.0),glm::dvec3(x,y,z)); //currMatrix[0][3] += x; //currMatrix[1][3] += y; //currMatrix[2][3] += z; //currMatrix.a03 += x; // currMatrix.a13 += y; //currMatrix.a23 += z; //printMatrix(currMatrix); } else if (!strcmp(command, "rotate")) { double ang, x,y,z ; // Rotate by an angle about axis x y z as in standard OpenGL int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf",command, &x, &y, &z, &ang) ; if (num != 5) { fprintf(stderr, "rotate angle x y z\n") ; exit(1) ; } glm::dvec3 tempVec =glm::dvec3 (x,y,z); tempVec = glm::normalize(tempVec); helper = glm::dmat4(1.0); //helper.set_rot(ang*PI/180.0,tempVec); double angle = ang*PI/180.0; helper = glm::rotate(helper,angle,tempVec); helper2=currMatrix; currMatrix=helper2*helper; } else if (!strcmp(command, "rotatex")) { double ang; // Rotate by an angle about x axis as in standard OpenGL int num = sscanf(line.c_str(), "%s %lf ",command, &ang) ; if (num != 2) { fprintf(stderr, "rotatex angle \n") ; exit(1) ; } helper = glm::dmat4(1.0); //helper.set_rotx(ang*PI/180.0); double angle = ang*PI/180.0; helper = glm::rotate(helper,angle,glm::dvec3(1,0,0)); helper2=currMatrix; currMatrix = helper2 * helper; } else if (!strcmp(command, "rotatey")) { double ang; // Rotate by an angle about x axis as in standard OpenGL int num = sscanf(line.c_str(), "%s %lf ",command, &ang) ; if (num != 2) { fprintf(stderr, "rotatey angle \n") ; exit(1) ; } helper = glm::dmat4(1.0); //helper.set_roty(ang*PI/180.0); double angle = ang*PI/180.0; helper = glm::rotate(helper,angle,glm::dvec3(0,1,0)); helper2=currMatrix; currMatrix=helper2*helper; } else if (!strcmp(command, "rotatez")) { double ang; // Rotate by an angle about x axis as in standard OpenGL int num = sscanf(line.c_str(), "%s %lf ",command, &ang) ; if (num != 2) { fprintf(stderr, "rotatez angle \n") ; exit(1) ; } helper = glm::dmat4(1.0); //helper.set_rotz(ang*PI/180.0); double angle = angle*PI/180.0; helper = glm::rotate(helper,ang,glm::dvec3(0,0,1)); helper2=currMatrix; currMatrix = helper2*helper; } else if (!strcmp(command, "scale")) { double x,y,z ; // Scale by x y z as in standard OpenGL int num = sscanf(line.c_str(), "%s %lf %lf %lf",command, &x, &y, &z) ; if (num != 4) { fprintf(stderr, "scale x y z\n") ; exit(1) ; } helper = glm::dmat4(1.0); helper[0][0]=x; helper[1][1]=y; helper[2][2]=z; helper2=currMatrix; currMatrix = helper2 * helper; } else if (!strcmp(command, "pushTransform")) { glm::dmat4 newMat(1.0); newMat = currMatrix; transforms.push_back(newMat); // Push the current matrix on the stack as in OpenGL } else if (!strcmp(command, "popTransform")) { currMatrix = transforms.back(); // Pop the current matrix as in OpenGL transforms.pop_back(); } else if (!strcmp(command, "maxdepth")) { int num = sscanf(line.c_str(), "%s %d", command, &maxdepth) ; assert(num == 2) ; assert(!strcmp(command, "maxdepth")) ; *maxD=maxdepth; std::cout<<" maxdepth: "<<*maxD<<std::endl; } else if (!strcmp(command, "output")) { char out[300] ; int num = sscanf(line.c_str(), "%s %s", command, out) ; assert(num == 2) ; assert(!strcmp(command, "output")) ; //output->assign(out); //std::cout<<*output<<std::endl; } /*************************************************/ /*************** LIGHTS *******************/ else if (!strcmp(command, "directional")) { double direction[4], color[4] ; color[3] = 1.0 ; direction[3] = 0.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf %lf %lf", command, direction, direction+1, direction+2, color, color+1, color+2) ; assert(num == 7) ; glm::dvec3 temp(direction[0],direction[1],direction[2]); glm::dvec3 temp2=temp; glm::normalize(temp2); Color tempC(color[0],color[1],color[2]); Light* tempLight = new DirectionalLight(temp,tempC,temp2); tracer->AddLight(tempLight); } else if (!strcmp(command, "point")) { double position[4], color[4] ; color[3] = 1.0 ; position[3] = 1.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf %lf %lf", command, position, position+1, position+2, color, color+1, color+2) ; assert(num == 7); glm::dvec3 temp(position[0],position[1],position[2]); Color tempC(color[0],color[1],color[2]); Light* tempLight = new PointLight(temp,tempC,temp); //((PointLight*)tempLight)->SetAttenuation(attenuation[0],attenuation[1],attenuation[2]); tracer->AddLight(tempLight); } else if (!strcmp(command, "arealight")) { double direction[4], color[4]; double length = 0.0; int samples = 0; color[3] = 1.0; direction[3] = 1.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf %lf %lf %lf %lf %d", command, direction, direction+1, direction+2, color, color+1, color+2, &length, &samples) ; assert(num == 9); glm::dvec3 temp(direction[0],direction[1],direction[2]); Color tempC(color[0],color[1],color[2]); Light* tempLight = new AreaLight(temp,tempC,temp,length,samples); ((AreaLight*)tempLight)->SetAttenuation(attenuation[0],attenuation[1],attenuation[2]); tracer->AddLight(tempLight); } else if (!strcmp(command, "attenuation")) { int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, attenuation, attenuation + 1, attenuation +2) ; assert(num == 4) ; assert(!strcmp(command, "attenuation")) ; // this changes the attenuation and // whenever we set a point light, // since attenuation is a global variable, // these are the values used to set // its attenuation } else if (!strcmp(command, "ambient")) { double ambient[4] ; ambient[3] = 1.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, ambient, ambient+1, ambient+2) ; assert(num == 4) ; assert(!strcmp(command, "ambient")) ; // changes the ka in the tempBRDF used to set primitives' material tempBRDF.SetKa(Color(ambient[0],ambient[1],ambient[2])); } /*******************************************************/ /****************** MATERIALS ************************/ else if (!strcmp(command, "diffuse")) { double diffuse[4] ; diffuse[3] = 1.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, diffuse, diffuse+1, diffuse+2) ; assert(num == 4) ; assert (!strcmp(command, "diffuse")) ; // changes the kd in the tempBRDF used to set primitives' material tempBRDF.SetKd(Color(diffuse[0],diffuse[1],diffuse[2])); } else if (!strcmp(command, "specular")) { double specular[4] ; specular[3] = 1.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, specular, specular+1, specular+2) ; assert(num == 4) ; assert (!strcmp(command, "specular")) ; // changes the Ks in the tempBRDF used to set primitives' material tempBRDF.SetKs(Color(specular[0],specular[1],specular[2])); } else if (!strcmp(command, "shininess")) { double shininess ; int num = sscanf(line.c_str(), "%s %lf", command, &shininess) ; assert(num == 2) ; assert (!strcmp(command, "shininess")) ; // changes the s (shininess) in the tempBRDF used to set primitives' material tempBRDF.SetS(shininess); } else if (!strcmp(command, "emission")) { double emission[4] ; emission[3] = 1.0 ; int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, emission, emission+1, emission+2) ; assert(num == 4) ; assert (!strcmp(command, "emission")) ; // changes the Ke in the tempBRDF used to set primitives' material tempBRDF.SetKe(Color(emission[0],emission[1],emission[2])); } else if (!strcmp(command, "reflection")) { double reflection[3]; int num = sscanf(line.c_str(), "%s %lf %lf %lf", command, reflection, reflection+1, reflection+2) ; assert(num == 4) ; assert (!strcmp(command, "reflection")) ; // changes the Kr in the tempBRDF used to set primitives' material tempBRDF.SetKr(Color(reflection[0],reflection[1],reflection[2])); } else if (!strcmp(command, "refraction")) { double refraction; int num = sscanf(line.c_str(), "%s %lf", command, &refraction) ; assert(num == 2) ; assert (!strcmp(command, "refraction")) ; // changes the Kt in the tempBRDF used to set primitives' material tempBRDF.SetKt(refraction); } /*****************************************************/ else { fprintf(stderr, "Unimplemented command: %s\n", command) ; exit(1) ; } } vert=0; vertnorm=0; maxverts=0; maxvertnorms=0; curvert=0; curvertnorm=0; maxdepth=3; lightnum=0; parsed = 0 ; tnumber++; std::cout << "parsing ended successfully " << tnumber << std::endl; }
void WaterObject::drawUnderwaterFilter( SceneRenderState *state ) { // set up camera transforms MatrixF proj = GFX->getProjectionMatrix(); MatrixF newMat(true); GFX->setProjectionMatrix( newMat ); GFX->pushWorldMatrix(); GFX->setWorldMatrix( newMat ); // set up render states GFX->disableShaders(); GFX->setStateBlock( mUnderwaterSB ); /* const Frustum &frustum = state->getFrustum(); const MatrixF &camXfm = state->getCameraTransform(); F32 nearDist = frustum.getNearDist(); F32 nearLeft = frustum.getNearLeft(); F32 nearRight = frustum.getNearRight(); F32 nearTop = frustum.getNearTop(); F32 nearBottom = frustum.getNearBottom(); Point3F centerPnt; frustum.getCenterPoint( ¢erPnt ); MatrixF.mul Point3F linePnt, lineDir; if ( mIntersect( nearPlane, mWaterPlane, &linePnt, &lineDir ) ) { Point3F leftPnt( centerPnt ); leftPnt.x = near } */ Point2I resolution = GFX->getActiveRenderTarget()->getSize(); F32 copyOffsetX = 1.0 / resolution.x; F32 copyOffsetY = 1.0 / resolution.y; /* ClippedPolyList polylist; polylist.addPoint( Point3F( -1.0f - copyOffsetX, -1.0f + copyOffsetY, 0.0f ) ); polylist.addPoint( Point3F( -1.0f - copyOffsetX, 1.0f + copyOffsetY, 0.0f ) ); polylist.addPoint( Point3F( 1.0f - copyOffsetX, 1.0f + copyOffsetY, 0.0f ) ); polylist.addPoint( Point3F( 1.0f - copyOffsetX, -1.0f + copyOffsetY, 0.0f ) ); polylist.addPlane( clipPlane ); polylist.begin( NULL, 0 ); polylist.vertex( 0 ); polylist.vertex( 1 ); polylist.vertex( 2 ); polylist.vertex( 0 ); polylist.vertex( 2 ); polylist.vertex( 3 ); */ // draw quad GFXVertexBufferHandle<GFXVertexPC> verts( GFX, 4, GFXBufferTypeVolatile ); verts.lock(); verts[0].point.set( -1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0 ); verts[0].color = mUnderwaterColor; verts[1].point.set( -1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0 ); verts[1].color = mUnderwaterColor; verts[2].point.set( 1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0 ); verts[2].color = mUnderwaterColor; verts[3].point.set( 1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0 ); verts[3].color = mUnderwaterColor; verts.unlock(); GFX->setVertexBuffer( verts ); GFX->drawPrimitive( GFXTriangleFan, 0, 2 ); // reset states / transforms GFX->setProjectionMatrix( proj ); GFX->popWorldMatrix(); }
int main(int argc, char *argv[]) { int i,j,k,nn; int imax,jmax,kmax,mimax,mjmax,mkmax,msize[3]; float gosa; double cpu0,cpu1,cpu,flop; // hardcode to S size msize[0]= 64; msize[1]= 64; msize[2]= 128; mimax= msize[0]; mjmax= msize[1]; mkmax= msize[2]; imax= mimax-1; jmax= mjmax-1; kmax= mkmax-1; printf("mimax = %d mjmax = %d mkmax = %d\n",mimax,mjmax,mkmax); printf("imax = %d jmax = %d kmax =%d\n",imax,jmax,kmax); /* * Initializing matrixes */ newMat(&p,1,mimax,mjmax,mkmax); newMat(&bnd,1,mimax,mjmax,mkmax); newMat(&wrk1,1,mimax,mjmax,mkmax); newMat(&wrk2,1,mimax,mjmax,mkmax); newMat(&a,4,mimax,mjmax,mkmax); newMat(&b,3,mimax,mjmax,mkmax); newMat(&c,3,mimax,mjmax,mkmax); mat_set_init(&p); mat_set(&bnd,0,1.0); mat_set(&wrk1,0,0.0); mat_set(&wrk2,0,0.0); mat_set(&a,0,1.0); mat_set(&a,1,1.0); mat_set(&a,2,1.0); mat_set(&a,3,1.0/6.0); mat_set(&b,0,0.0); mat_set(&b,1,0.0); mat_set(&b,2,0.0); mat_set(&c,0,1.0); mat_set(&c,1,1.0); mat_set(&c,2,1.0); /* * Start measuring */ nn= 64; gosa = jacobi(nn,&a,&b,&c,&p,&bnd,&wrk1,&wrk2); printf(" Loop executed for %d times\n",nn); printf(" Gosa : %e \n",gosa); /* * Matrix free */ clearMat(&p); clearMat(&bnd); clearMat(&wrk1); clearMat(&wrk2); clearMat(&a); clearMat(&b); clearMat(&c); return (0); }