Exemplo n.º 1
0
void Frustum::buildFromPolygon(const Vector3f *points,const int numPoints,const Matrix4f &viewmatrix)
{
	planes->clear();

	Plane plane;
	Matrix4f matr=viewmatrix;
	
	Matrix4f matri=matr/*.invert()*/;
	Vector4f tempv(0.0f,0.0f,0.0f,1.0f);
	tempv=Vector4f(matri*tempv);
	Vector3f viewpos(tempv.x(),tempv.y(),tempv.z());
//	Kernel::logger() << "x " << tempv.x() << " y " << tempv.y() << " z " << tempv.z() << "\n";
	
	for (int point=0;point<numPoints;++point) {
		Vector3f point1=points[point];
		Vector3f point2=points[(point+1)%numPoints];
		
		Vector3f vec1=point2-viewpos;
		Vector3f vec2=point2-point1;
		Vector3f normal=vec1^vec2;
		normal.normalize();
		plane.normal(normal);
		plane.d(normal*viewpos);
//		Kernel::logger() << "a " << plane.a() << " b " << plane.b() << " c " << plane.c() << " d " << plane.d() << "\n";
		
		planes->push_back(plane);
	}
}
Exemplo n.º 2
0
inline void setInvalidHistoryFact() {
  if(!InvalidHistoryFact_p) {
    Variable tempv("InvalidHistoryRule");
    Monomial tempm;
    tempm *= tempv;
    Polynomial tempp;
    RECORDHERE(InvalidHistoryFact_p = new GroebnerRule(tempm,tempp);)
Exemplo n.º 3
0
double snake::math::average(LaGenMatComplex &mat,LaVectorComplex &v)
{
  double z;
  z = Blas_H_Dot_Prod(v,v).r;
  LaVectorComplex tempv(v);
  Blas_Mat_Vec_Mult(mat,v,tempv);
  return Blas_H_Dot_Prod(v,tempv).r/z;
}
Exemplo n.º 4
0
double snake::math::average(LaGenMatDouble &mat,LaVectorDouble &v)
{
  double z;
  z = Blas_Dot_Prod(v,v);
  LaVectorDouble tempv(v);
  Blas_Mat_Vec_Mult(mat,v,tempv);
  return Blas_Dot_Prod(v,tempv)/z;
}
Exemplo n.º 5
0
 void WorldObject::AttachToGraphics()
 {
     if(GraphicsNode && GraphicsObject)
     {
         Vector3 tempv(PhysicsObject->getWorldTransform().getOrigin());
         Quaternion tempq(PhysicsObject->getWorldTransform().getRotation());
         this->GraphicsNode->setPosition(tempv.GetOgreVector3());
         this->GraphicsNode->setOrientation(tempq.GetOgreQuaternion());
         this->GraphicsNode->attachObject(this->GraphicsObject);
     }
 }
Exemplo n.º 6
0
///Be carefull that v1,v2 will not be normalized
COMPLEX snake::math::average(LaVectorComplex &v1,LaGenMatComplex &mat,LaVectorComplex &v2)
{
  COMPLEX z;
  // std::cout<<v2<<std::endl;
  LaVectorComplex tempv(v2.size());
  //std::cout<<tempv<<std::endl;
  Blas_Mat_Vec_Mult(mat,v2,tempv);

  z = snake::math::Dot_Prod(v1,tempv);
  //std::cout<<LaComplex(z)<<std::endl;
  return z;
}
Exemplo n.º 7
0
void object::GetPosition(float &x, float &y, float &z)
{
	D3DXMATRIX mat;
	D3DXMATRIX temp;
	D3DXVECTOR3 tempv(0,0,0);
	
	D3DXMatrixIdentity(&matworld);
	D3DXMatrixTranslation(&temp,radius_of_rotation,0,0);
	D3DXMatrixMultiply( &matworld, &matworld, &temp );
	D3DXMatrixRotationY(&temp,angle);
	D3DXMatrixMultiply( &matworld, &matworld, &temp );
	D3DXMatrixTranslation(&temp,center_pos.x,center_pos.y,center_pos.z);
	D3DXMatrixMultiply( &matworld, &matworld, &temp );

	D3DXVec3TransformCoord(&tempv,&tempv,&matworld);
	
	x = tempv.x;
	y = tempv.y;
	z = tempv.z;
}
Exemplo n.º 8
0
void Raytracer::render( int width, int height, Point3D eye, Vector3D view, 
		Vector3D up, double fov, char* fileName, int aa, int fl, bool dof ) {
	Matrix4x4 viewToWorld;

	width = width * aa;
	height = height * aa;
	double factor = (double(height)/2)/tan(fov*M_PI/360.0);

	viewToWorld = initInvViewMatrix(eye, view, up);

	initAABuffer(aa, width, height);

	_scrWidth = width / aa;
	_scrHeight = height / aa;

	initPixelBuffer();

	// Construct a ray for each pixel.
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			// Sets up ray origin and direction in view space, 
			// image plane is at z = -1.
			Point3D origin(0, 0, 0);
			Point3D imagePlane;
			imagePlane[0] = (-double(width)/2 + 0.5 + j)/factor;
			imagePlane[1] = (-double(height)/2 + 0.5 + i)/factor;
			imagePlane[2] = -1;
			
			Ray3D ray;

			ray.origin = viewToWorld * origin;
            ray.dir = viewToWorld * imagePlane - ray.origin;
			ray.dir.normalize();
			Colour col(0,0,0);

			//implement depth of field if true
			if (dof == true) {
				//generate a point in the scene as part of the focal plane
				Vector3D pointAimed = (ray.origin + fl * ray.dir) - Point3D(0,0,0);
				float r = 1;
				Colour pc(0,0,0);

				for (int px=0; px < 15; px++) {
					float du = ((float) rand())/(float(RAND_MAX));
					float dv = ((float) rand())/(float(RAND_MAX));
					//x and y axis of camera/eye
					Vector4D u = viewToWorld.getColumn(1);
					Vector4D v = viewToWorld.getColumn(0);
					//convert them to 3d vectors;
					Vector3D u2(u[0],u[1],u[2]);
					Vector3D v2(v[0],v[1],v[2]);
					//convert ray.origin to vector for vector operation;
					Vector3D tempv(ray.origin[0], ray.origin[1], ray.origin[2]);
					//generate random point around the eye (vector is used for operation)
					Vector3D eyev = tempv - (r/2)*u2 - (r/2)*v2 + r*(du)*u2 + r*(dv)*v2;
					//generate a ray from random point to pointAimed
					Ray3D dovr;
					dovr.dir = pointAimed - eyev;
					dovr.origin = Point3D(eyev[0], eyev[1], eyev[2]);
					dovr.dir.normalize();
					//bounce ray into the scene and get its color
					Colour dovCol = shadeRay(dovr, 2);
					pc = pc + dovCol;

				}
				//average the pixel colors to get the blurriness effect
				col = (1/15.0) * pc;
			} else {
				col = shadeRay(ray, 2);
			}
			col.clamp();

			if (aa == 1) {
				_rbuffer[i*width+j] = int(col[0]*255);
				_gbuffer[i*width+j] = int(col[1]*255);
				_bbuffer[i*width+j] = int(col[2]*255);
			} else {
				re[i*width+j] = int(col[0]*255);
				gr[i*width+j] = int(col[1]*255);
				bl[i*width+j] = int(col[2]*255);
			}

		}
	}

	if (aa == 1) {
		flushPixelBuffer(fileName);
	} else {
		aarender(width, height, aa, fileName);
		delete re;
		delete gr;
		delete bl;
	}
}