Пример #1
0
/**
 * Rotate the camera around the specified axis and the specified origin by the specified angle.
 *
 * @param axis		the axis 
 * @param angle		the angle
 * @param orig		the origin
 */
void PPC::RotateAbout(const V3& axis, float angle, const V3& orig) {
	a = a.RotateAbout(axis, angle);
	b = b.RotateAbout(axis, angle);
	c = c.RotateAbout(axis, angle);
	C = C.RotateAbout(axis, angle, orig);

	SetPMat();
}
Пример #2
0
PPC::PPC(float hfov,  int w, int h) : w(w), h(h) {
	a = V3(1.0f, 0.0f, 0.0f);
	b = V3(0.0f, -1.0f, 0.0f);
	C = V3(0.0f, 0.0f, 0.0f);
	float f = (float)w/2.0f/tanf(DEG2RAD(hfov/2.0f));
	c = V3(-(float)w/2.0f, (float)h/2.0f, -f);

	SetPMat();
}
Пример #3
0
PPC::PPC() {
	a = V3(1.0f, 0.0f, 0.0f);
	b = V3(0.0f, -1.0f, 0.0f);
	c = V3(0.0f, 0.0f, 0.0f);
	C = V3(0.0f, 0.0f, 0.0f);
	w = 0;
	h = 0;

	SetPMat();
}
Пример #4
0
/**
 * Setup this camera according to the specified center, vector a, and the view direction.
 *
 * @param C		the center of the camera
 * @param a		the vector a (The horizontal direction of the screen)
 * @param vd	the view direction of the camera
 */
void PPC::Set(const V3& C, const V3& a, const V3& vd) {
	this->C = C;
	this->a = a;

	b = (vd ^ a).UnitVector() * b.Length();

	c = vd.UnitVector() * GetFocalLength() - a * ((float)w/2.0f) - b * ((float)h/2.0f);

	SetPMat();
}
Пример #5
0
/**
 * Setup this camera such that it looks at the specified point with the specified view direction, up direction, and the distance from the point.
 *
 * @param p		the target point that this camera will look at
 * @param vd	the view direction
 * @param up	the up direction
 * @param d		the distance between the center of this camera and the target
 */
void PPC::LookAt(const V3 &p, const V3 &vd, const V3 &up, float d) {
	float f = GetFocalLength();

	C = p - vd.UnitVector() * d;
	a = (vd ^ up).UnitVector() * a.Length();
	b = (vd ^ a).UnitVector() * b.Length();
	c = vd.UnitVector() * f - a * ((float)w / 2.0f) - b * ((float)h / 2.0f);

	SetPMat();
}
Пример #6
0
void PPC::Roll(float rs){
	if(rs == 0){
		return;
	}

	//a = a.rotate(a.normalize(), rs);
	b = b.rotate(a.normalize(), rs);
	c = c.rotate(a.normalize(), rs);

	//setNearAndFarPoints();
	SetPMat();
}
Пример #7
0
void PPC::Pan(float rs){
	if(rs == 0){
		return;
	}

	a = a.rotate(b.normalize()*-1.0f, rs);
	//b = b.rotate(b.normalize()*-1.0f, rs);
	c = c.rotate(b.normalize()*-1.0f, rs);

	//setNearAndFarPoints();
	SetPMat();
}
Пример #8
0
void PPC::Load(char *fname){

	ifstream ifs(fname);
	ifs >> a ;
	ifs >> b ;
	ifs >> c ;
	ifs >> C ;
	ifs.close();

	//setNearAndFarPoints();
	SetPMat();
}
Пример #9
0
void PPC::Tilt(float rs){
	if(rs == 0){
		return;
	}

	a = a.rotate(GetVD().normalize(), rs);
	b = b.rotate(GetVD().normalize(), rs);
	c = c.rotate(GetVD().normalize(), rs);

	//setNearAndFarPoints();
	SetPMat();
}
Пример #10
0
PPC::PPC(float hfov, int _w, int _h) : w(_w), h(_h){
	C = Vector3D(0.0f, 0.0f, 0.0f);
	a = Vector3D(1.0f, 0.0f, 0.0f);
	b = Vector3D(0.0f, -1.0f, 0.0f);
	this->hfov = hfov;

	hfovR = hfov / 180.0f * PI;
	c = Vector3D(-((float)w)/2.0f, ((float)h)/2.0f, -(float)w/(2.0f*tanf(hfovR/2.0f)));
	
	zNear = 1.0f;
	zFar = 10000.0f;

	frustum = 0;
	frustumf = 0;

	//setNearAndFarPoints();
	SetPMat();
}
Пример #11
0
void PPC::zoom(float s, char S){
	if(s == 0.0f){
		return;
	}

	if(S == 'o'){
		s = 1.0f/s;
	}

	float f = Getf();
	float newf = f*s;

	Vector3D newc = newf * GetVD() + (float) w / 2.0f * (-1.0f * a) + (float)h / 2.0f * (-1.0f * b);

	c = newc;

	//setNearAndFarPoints();
	SetPMat();
}
Пример #12
0
/**
 * Change the focal length to the specified length.
 *
 * @param len		the new focal length
 */
void PPC::SetFocalLength(float len) {
	c = GetVD() * len - a * ((float)w/2.0f) - b * ((float)h/2.0f);
	SetPMat();
}
Пример #13
0
void PPC::Roll(float angle) {
	a = a.RotateAbout(GetVD(), -angle);
	b = a.RotateAbout(GetVD(), -angle);
	c = a.RotateAbout(GetVD(), -angle, C);
	SetPMat();
}
Пример #14
0
void PPC::Tilt(float angle) {
	b = b.RotateAbout(a, angle);
	c = c.RotateAbout(a, angle, C);
	SetPMat();
}
Пример #15
0
void PPC::Pan(float angle) {
	a = a.RotateAbout(b, -angle);
	c = c.RotateAbout(b, -angle, C);
	SetPMat();
}
Пример #16
0
/**
 * Load the camera object from the specified file.
 * All the data are stored in the file with a space as a delimiter.
 *
 * @param filename		the specified file name
 */
void PPC::Load(char* filename) {
	ifstream ifs(filename);
	ifs >> a >> b >> c >> C >> w >> h;
	SetPMat();
}