示例#1
0
文件: main.c 项目: AdelGit/openlase
void shader_cube(float *x, float *y, uint32_t *color)
{
	olPushMatrix3();
	olLoadIdentity3();

	// Shrink down the entire final image a bit, to avoid cutting off the cube's
	// left and right corners while it's rotating. On a bitmap display (PC) this
	// doesn't matter, but on the laser without shading it looks bad if the edge
	// suddenly scissors off.
	olScale3( 0.9, 0.9, 0.9);

	// This transform sets it up so that it's identity at the cube's front face
	// (z = -4)
	olFrustum(-1, 1, -1, 1, FACEDEPTH, 100);

	// Now figure out the z-position depending on the rotation of the cube, to
	// make the frontmost edge always be full-height.
	float theta = cubepos < 0 ? -cubepos : cubepos;
	float zdelta = -1 - FACEDEPTH + 1 * (sinf(M_PI/4) - sinf(M_PI/4 + theta));
	olTranslate3(0, 0, zdelta);

	// Perform the rotation
	olRotate3Y(cubepos);

	// And finally transform the incoming vertex
	float z = 1;
	olTransformVertex3(x, y, &z);

	olPopMatrix3();
}
示例#2
0
static VALUE
ol_rotate3Y(VALUE self, VALUE v)
{
  olRotate3Y(NUM2DBL(v));
  return Qnil;
}
示例#3
0
int main (int argc, char *argv[])
{
	OLRenderParams params;

	memset(&params, 0, sizeof params);
	params.rate = 48000;
	params.on_speed = 2.0/100.0;
	params.off_speed = 2.0/20.0;
	params.start_wait = 8;
	params.start_dwell = 3;
	params.curve_dwell = 0;
	params.corner_dwell = 8;
	params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg
	params.end_dwell = 3;
	params.end_wait = 7;
	params.snap = 1/100000.0;
	params.render_flags = RENDER_GRAYSCALE;

	if(olInit(3, 30000) < 0)
		return 1;

	olSetRenderParams(&params);

	float time = 0;
	float ftime;
	int i,j;

	int frames = 0;

	while(1) {
		olLoadIdentity3();
		olLoadIdentity();
		olPerspective(60, 1, 1, 100);
		olTranslate3(0, 0, -3);

		for(i=0; i<2; i++) {
                  if (i == 1)
                    olColor3(0.0,1.0,0.0);
                  else
                    olColor3(0.0,1.0,0.0);

                  olScale3(0.6, 0.6, 0.6);

                  olRotate3Z(time * M_PI * 0.1);
                  olRotate3Y(time * M_PI * 0.8);
                  olRotate3X(time * M_PI * 0.73);

                  olBegin(OL_LINESTRIP);
                  olVertex3(-1, -1, -1);
                  olVertex3( 1, -1, -1);
                  olVertex3( 1,  1, -1);
                  olVertex3(-1,  1, -1);
                  olVertex3(-1, -1, -1);
                  olVertex3(-1, -1,  1);
                  olEnd();

                  olBegin(OL_LINESTRIP);
                  olVertex3( 1,  1,  1);
                  olVertex3(-1,  1,  1);
                  olVertex3(-1, -1,  1);
                  olVertex3( 1, -1,  1);
                  olVertex3( 1,  1,  1);
                  olVertex3( 1,  1, -1);
                  olEnd();

                  olBegin(OL_LINESTRIP);
                  olVertex3( 1, -1, -1);
                  olVertex3( 1, -1,  1);
                  olEnd();

                  olBegin(OL_LINESTRIP);
                  olVertex3(-1,  1,  1);
                  olVertex3(-1,  1, -1);
                  olEnd();
		}

		ftime = olRenderFrame(60);
		frames++;
		time += ftime;
		printf("Frame time: %f, FPS:%f\n", ftime, frames/time);
	}

	olShutdown();
	exit (0);
}
示例#4
0
文件: demo.c 项目: marcan/openlase
void render_cubes(float time)
{
	int i;

	OLRenderParams mpar;

	memcpy(&mpar, &params, sizeof(OLRenderParams));

	if (time > 32) {
		time += 1.0;
		mpar.on_speed = 0.022 + (1-usin(time, 2.0)) * 0.02;
		mpar.corner_dwell = 8*usin(time, 2.0);
		mpar.start_dwell = 2+3*usin(time, 2.0);
		mpar.start_wait = 3+5*usin(time, 2.0);
		mpar.end_dwell = 2+3*usin(time, 2.0);
		mpar.end_wait = 2*usin(time, 2.0);
		olSetRenderParams(&mpar);
		time -= 1.0;
	}
	printf("%f %d %d %d %d %d\n", mpar.on_speed, mpar.corner_dwell, mpar.start_dwell, mpar.start_wait, mpar.end_dwell, mpar.end_wait);

	olLoadIdentity3();
	olPerspective(60, 1, 1, 100);
	olTranslate3(0, 0, -2.1);

	for(i=0; i<3; i++) {
		if (i>0)
			olPushMatrix3();
		olScale3(0.6, 0.6, 0.6);
		if (i>0) {
			float tx = sinf(time + (i-1)*M_PI);
			float ty = cosf(time + (i-1)*M_PI);
			float tz = sinf(time + (i-1)*M_PI);
			float s = sinf(0.6*time);
			olTranslate3(tx*s,ty*s,tz*s);
			//olScale3(s,s,s);
			olScale3(0.3,0.3,0.3);
		}

		float mult;
		if (i==0)
			mult = 1;
		else if (i==1)
			mult = 1.5;
		else if (i==2)
			mult = -1.5;

		if (i==0)
			olMultColor(C_GREY(120));
		else
			olResetColor();



		olRotate3Z(mult*time * M_PI * 0.1 / 3.0);
		olRotate3Y(mult*time * M_PI * 0.8 / 3.0);
		olRotate3X(mult*time * M_PI * 0.73 / 3.0);

		olBegin(OL_LINESTRIP);
		olVertex3(-1, -1, -1, C_RED);
		olVertex3( 1, -1, -1, C_RED);
		olVertex3( 1,  1, -1, C_RED);
		olVertex3(-1,  1, -1, C_RED);
		olVertex3(-1, -1, -1, C_RED);
		olVertex3(-1, -1,  1, C_RED);
		olEnd();

		olBegin(OL_LINESTRIP);
		olVertex3( 1,  1,  1, C_GREEN);
		olVertex3(-1,  1,  1, C_GREEN);
		olVertex3(-1, -1,  1, C_GREEN);
		olVertex3( 1, -1,  1, C_GREEN);
		olVertex3( 1,  1,  1, C_GREEN);
		olVertex3( 1,  1, -1, C_GREEN);
		olEnd();

		olBegin(OL_LINESTRIP);
		olVertex3( 1, -1, -1, C_RED);
		olVertex3( 1, -1,  1, C_RED);
		olEnd();

		olBegin(OL_LINESTRIP);
		olVertex3(-1,  1,  1, C_GREEN);
		olVertex3(-1,  1, -1, C_GREEN);
		olEnd();

		/*olBegin(OL_BEZIERSTRIP);
		olVertex3(-1, 1, 0, C_WHITE);
		olVertex3(0, -1, 0, C_WHITE);
		olVertex3(0, -1, 0, C_WHITE);
		olVertex3(1, 1, 0, C_WHITE);
		olVertex3(-1, 0, 0, C_WHITE);
		olVertex3(-1, 0, 0, C_WHITE);
		olVertex3(1, -1, 0, C_WHITE);
		olVertex3(0, 1, 0, C_WHITE);
		olVertex3(0, 1, 0, C_WHITE);
		olVertex3(-1, -1, 0, C_WHITE);
		olVertex3(1, 0, 0, C_WHITE);
		olVertex3(1, 0, 0, C_WHITE);
		olVertex3(-1, 1, 0, C_WHITE);
		olEnd();*/
		if (i>0)
			olPopMatrix3();
	}
	olLoadIdentity3();
	olLoadIdentity();
	olSetRenderParams(&params);
	olResetColor();
}