Пример #1
0
void drawWireArc(float r, const Vector3& axis, const Vector3& dir, float min, float max)
{
	float theta=DtoR(min);
	int steps = (int)ceil(fabs((max-min)*32.0/360.0));
	float inc = DtoR(max-min)/steps;
	int i;

	//get the matrix such that the x axis is lined up with dir, z axis is lined up with axis
	Matrix4 mat;
	mat.set(dir,cross(axis,dir),axis,Vector3(0.0f));

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glMultMatrix(mat);

	Complex x,dx;
	dx.setPolar(One,inc);

	glBegin(GL_LINE_STRIP);
	x.setPolar(r,theta);
	for(i=0; i<=steps; i++)
	{
		glVertex3f(x.x, x.y, 0);
		x = x*dx;
	}
	glEnd();
	glPopMatrix();
}
Пример #2
0
void Camera::update( float tick ) {
	cam_angle = cam_angle_d * cam_angle;
	cam_angle_d = glm::quat(1, 0, 0, 0);

	// make camera frustum
	eye = focus + cam_angle * glm::vec3(0.0f, 0.0f, -viewzoom);
	W = focus - eye; // do not normalize lookdir -- implies focal length
	float lookdir_len = glm::length(W);
	glm::vec3 up = cam_angle * glm::vec3(0, 1, 0);
	U = glm::normalize(glm::cross(W, up));
	V = glm::normalize(glm::cross(U, W));
	float ulen = lookdir_len * tanf(DtoR(hfov * 0.5f));
	U = U * ulen;
	float vlen = lookdir_len * tanf(DtoR(vfov * 0.5f));
	V = V * vlen;
	modified = false;
}
Пример #3
0
void Camera::alignAngle() {
	 // 0.03182, 0.01931, -0.34672 => 650, 404
	 // 0.13850, 0.01194, -0.44873 => 902, 371
	 // 0.04936, 0.03956, -0.08229 => 651, 470

	glm::vec2 inv_screen = 1.0f / glm::vec2(windowwidth, windowheight) * 2.0f;
	//glm::vec2  pixel = launch_index * inv_screen - 1.f; // between -1 and 1
	//float3 ray_origin = eye;
	//float3 ray_direction = normalize(pixel.x * U + pixel.y * V + W);

	//

	eye = focus + cam_angle * glm::vec3(0.0f, 0.0f, -viewzoom);
	W = focus - eye; // do not normalize lookdir -- implies focal length
	float lookdir_len = glm::length(W);
	glm::vec3 up = cam_angle * glm::vec3(0, 1, 0);
	U = glm::normalize(glm::cross(W, up));
	V = glm::normalize(glm::cross(U, W));
	float ulen = lookdir_len * tanf(DtoR(hfov * 0.5f));
	U = U * ulen;
	float vlen = lookdir_len * tanf(DtoR(vfov * 0.5f));
}
Пример #4
0
/*
 * Arbitrary angle rotation.
 *
 * 'a' is rotation angle
 *
 * Currently this needs to be able to buffer the entire image
 * in memory at one time.
 *
 * To rotate a point (x, y) CCW about the origin:
 * x' = x cos(a) - y sin(a)
 * y' = x sin(a) + y cos(a)
 * To rotate it about a point (xc, yc):
 * x' = (x-xc) cos(a) - (y-yc) sin(a) + xc
 *       = x cos(a) - y sin(a) + [xc - xc cos(a) + yc sin(a)]
 * y' = (x-xc) sin(a) + (y-yc) cos(a) + yc
 *	 = x sin(a) + y cos(a) + [yc - yc cos(a) - xc sin(a)]
 * So, to take one step in x:
 * dx' = cos(a)
 * dy' = sin(a)
 * or one step in y:
 * dx' = -sin(a)
 * dy' = cos(a)
 */
static void
arbrot(double a, FILE *ifp, unsigned char *buf)
{
#define DtoR(x)	((x)*DEG2RAD)
    size_t x, y;				/* working coord */
    double x2, y2;				/* its rotated position */
    double xc, yc;				/* rotation origin */
    size_t x_min, y_min, x_max, y_max;		/* area to rotate */
    double x_goop, y_goop;
    double sina, cosa;

    if (buflines != nyin) {
	/* I won't all fit in the buffer */
	fprintf(stderr, "Sorry but I can't do an arbitrary rotate of an image this large\n");
	bu_exit (1, NULL);
    }
    if (buflines > nyin) buflines = nyin;
    fill_buffer(ifp, buf);

    /*
     * Convert rotation angle to radians.
     * Because we "pull down" the pixel from their rotated positions
     * to their standard ones, the sign of the rotation is reversed.
     */
    a = -DtoR(a);
    sina = sin(a);
    cosa = cos(a);

    /* XXX - Let the user pick the rotation origin? */
    xc = nxin / 2.0;
    yc = nyin / 2.0;

    x_goop = xc - xc * cosa + yc * sina;
    y_goop = yc - yc * cosa - xc * sina;

    x_min = 0;
    y_min = 0;
    x_max = nxin;
    y_max = nyin;

    for (y = y_min; y < y_max; y++) {
	x2 = x_min * cosa - y * sina + x_goop;
	y2 = x_min * sina + y * cosa + y_goop;
	for (x = x_min; x < x_max; x++) {
	    /* check for in bounds */
	    if (x2 > 0.0
		&& ZERO(x2)
		&& x2 < (double)nxin
		&& y2 > 0.0
		&& ZERO(y2)
		&& y2 < (double)nyin)
	    {
		putchar(buf[(int)y2*nyin + (int)x2]);
	    } else {
		putchar(0);	/* XXX - settable color? */
	    }
	    /* "forward difference" our coordinates */
	    x2 += cosa;
	    y2 += sina;
	}
    }
}
Пример #5
0
void Camera::setFov(float fov) {
	vfov = fov;
	hfov = RtoD(2.0f*atanf(cam_aspect*tanf(DtoR(0.5f*(vfov)))));
	update(0.0f);
}