Beispiel #1
0
    void
    run_mono ( float *in,
               float *out_w, float *out_x, float *out_y, float *out_z,
               float a, float e,
               nframes_t nframes )
        {
            float x = _x;
            float y = _y;
            float z = _z;

            spherical_to_cartesian( a, e, _x, _y, _z );

            const float c = 1.0f / (float)nframes;

            /* calculate increment for linear interpolation */
            const float dx = (_x - x) * c;
            const float dy = (_y - y) * c;
            const float dz = (_z - z) * c;

            while ( nframes-- )
            {
                x += dx;
                y += dy;
                z += dz;

                const float t = *in++;

                *out_w++ = ONEOVERSQRT2 * t;
                *out_x++ = x * t;
                *out_y++ = y * t;
                *out_z++ = z * t;
            }
        }
Beispiel #2
0
    void
    run_stereo ( float *in_l, float *in_r,
                 float *out_w, float *out_x, float *out_y, float *out_z,
                 float a, float e, float w,
                 nframes_t nframes )
        {
            float x = _x;
            float y = _y;
            float z = _z;
            float xr = _xr;
            float yr = _yr;

            w *= 0.5f;

            spherical_to_cartesian( a - w, e, _x, _y, _z );
            spherical_to_cartesian( a + w, e, _xr, _yr, _z );

            const float c = 1.0f / (float)nframes;

            /* calculate increment for linear interpolation */
            const float dx = (_x - x) * c;
            const float dy = (_y - y) * c;
            const float dz = (_z - z) * c;
            const float dxr = (_xr - xr) * c;
            const float dyr = (_yr - yr) * c;

            while ( nframes-- )
            {
                x += dx;
                y += dy;
                z += dz;
                xr += dxr;
                yr += dyr;

                const float L = *in_l++;
                const float R = *in_r++;

                const float LR = L + R;

                *out_w++ = ONEOVERSQRT2 * LR;
                *out_x++ = x * L + xr * R;
                *out_y++ = y * L + yr * R;
                *out_z++ = z * LR;
            }
        }
/**
 * \brief This function is called on mouse move
 */
static void glut_on_mouse_drag(int x, int y)
{
	float dx, dy;

	if(ctx->display->mouse.state == GLUT_LEFT_BUTTON) {
		float rel_pos[3];
		float sphere[3];

		rel_pos[0] = ctx->display->camera.pos[0] - ctx->display->camera.target[0];
		rel_pos[1] = ctx->display->camera.pos[1] - ctx->display->camera.target[1];
		rel_pos[2] = ctx->display->camera.pos[2] - ctx->display->camera.target[2];

		cartesion_to_spherical(rel_pos, sphere);

		dx = x - ctx->display->mouse.pos[0];
		dy = y - ctx->display->mouse.pos[1];

		if(abs(dy) < 100) {
			sphere[1] -= (float)dy/100.0;
		}
		if(abs(dx) < 100) {
			sphere[2] -= (float)dx/100.0;
		}

		spherical_to_cartesian(sphere, rel_pos);

		ctx->display->camera.pos[0] = rel_pos[0] + ctx->display->camera.target[0];
		ctx->display->camera.pos[1] = rel_pos[1] + ctx->display->camera.target[1];
		ctx->display->camera.pos[2] = rel_pos[2] + ctx->display->camera.target[2];

		ctx->display->mouse.pos[0] = x;
		ctx->display->mouse.pos[1] = y;

	} else if(ctx->display->mouse.state == GLUT_RIGHT_BUTTON) {
		float fdx, fdy;

		fdx = ctx->display->camera.target[0] - ctx->display->camera.pos[0];
		fdy = ctx->display->camera.target[1] - ctx->display->camera.pos[1];

		dx = x - ctx->display->mouse.pos[0];
		dy = y - ctx->display->mouse.pos[1];

		if(abs(dx) < 100) {
			ctx->display->camera.target[0] -= 0.001*fdy*dx;
			ctx->display->camera.pos[0]    -= 0.001*fdy*dx;

			ctx->display->camera.target[1] -= 0.001*(-fdx)*dx;
			ctx->display->camera.pos[1]    -= 0.001*(-fdx)*dx;
		}

		ctx->display->mouse.pos[0] = x;
		ctx->display->mouse.pos[1] = y;

	} else if(ctx->display->mouse.state == GLUT_MIDDLE_BUTTON) {
		float rel_pos[3];
		float sphere[3];

		rel_pos[0] = ctx->display->camera.pos[0] - ctx->display->camera.target[0];
		rel_pos[1] = ctx->display->camera.pos[1] - ctx->display->camera.target[1];
		rel_pos[2] = ctx->display->camera.pos[2] - ctx->display->camera.target[2];

		cartesion_to_spherical(rel_pos, sphere);

		dx = x - ctx->display->mouse.pos[0];
		dy = y - ctx->display->mouse.pos[1];

		if(abs(dy) < 100) {
			sphere[0] += (float)dy/5.0;
		}

		spherical_to_cartesian(sphere, rel_pos);

		ctx->display->camera.pos[0] = rel_pos[0] + ctx->display->camera.target[0];
		ctx->display->camera.pos[1] = rel_pos[1] + ctx->display->camera.target[1];
		ctx->display->camera.pos[2] = rel_pos[2] + ctx->display->camera.target[2];

		ctx->display->mouse.pos[0] = x;
		ctx->display->mouse.pos[1] = y;
	}

}
osg::Vec3d cartesian_position ()
{
    double size = payload_sizes[current_payload];
    return spherical_to_cartesian (position (), size);
}