Beispiel #1
0
void draw_cannon() {

        
        GLUquadricObj *quadric;
        quadric = gluNewQuadric();

        gluQuadricDrawStyle(quadric, GLU_FILL);
        gluQuadricTexture(quadric, GL_TRUE);

        /* Wheel 1 */
        glPushMatrix();
        glTranslatef ( 0.0 , 1.0 , 0.0 );
        draw_wheel() ;
        glPopMatrix();

        /* Wheel 2 */
        glPushMatrix();
        glTranslatef ( 0.0 , -1.0 , 0.0 );
        draw_wheel() ;
        glPopMatrix();

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture_granite);

        /* Barrel sits on this thing */
        glPushMatrix();
        glRotatef (90, 1.0, 0.0, 0.0);
        glTranslatef ( -3.0 , 0.0 , -0.6 );
        draw_barrel_leg() ;
        glPopMatrix();

        glPushMatrix();
        glRotatef (90, 1.0, 0.0, 0.0);
        glTranslatef ( -3.0 , 0.0 , 0.6 );
        draw_barrel_leg() ;
        glPopMatrix();

        /* Axle */
        glPushMatrix();
        glRotatef (90, 1.0, 0.0, 0.0);
        glTranslatef ( 0.0 , 1.0 , 0.0 );
        glTranslatef ( 0.0 , 0.0 , -1.0 );
        gluCylinder(quadric, 0.25, 0.25, 2.00, 30, 30);
        glPopMatrix();

        /* Barrel */
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture_granite);
        glPushMatrix();
            glTranslatef ( -2.0 , 0.0 , 0.0 );
            glTranslatef ( 0.0 , 0.0 , 1.0 );
            glRotatef ((GLfloat) 60.0, 0.0, 1.0, 0.0);
            gluCylinder(quadric, 0.5, 0.5, 3.00, 30, 30);
            gluSphere(quadric, 0.52 , 30, 30);
        glPopMatrix();
        glDisable(GL_TEXTURE_2D);

        gluDeleteQuadric(quadric);
}
Beispiel #2
0
void highlight_wheel(machine *m, ui_info *ui, int wheelnr) {
	int old = ui->chosen_wheel;
	ui->chosen_wheel = (wheelnr < m->wheelslots && wheelnr >= 0 )? wheelnr : -1;
	if (old == ui->chosen_wheel) return; /* no change */
	if (old >= 0) draw_wheel(m, ui, old);
	if (ui->chosen_wheel >= 0) draw_wheel(m, ui, ui->chosen_wheel);
	wnoutrefresh(ui->w_wheels);
}
Beispiel #3
0
/* Manual change of ring setting */
void ringstellung(machine *m, ui_info *ui, int step) {
	if (ui->chosen_wheel < 0) return;
	if (!m->slot[ui->chosen_wheel].step) return;
	int *i = &m->slot[ui->chosen_wheel].ringstellung;
	*i = (*i + m->alphabet_len + step) % m->alphabet_len;
	step_cleanup(m);
	draw_wheel(m, ui, ui->chosen_wheel);
	wnoutrefresh(ui->w_wheels);
}
Beispiel #4
0
/* Draw the set of wheels (entire window) */
void draw_wheels(machine *m, ui_info *ui) {
	for (int i = 0; i < m->wheelslots; ++i) draw_wheel(m, ui, i);
	/* Machine name centered on top */
	wattrset(ui->w_wheels, ui->attr_wheel_activ);
	mvwprintw(ui->w_wheels, 0, (getmaxx(ui->w_wheels)-wcslen(m->name))/2, "%ls", m->name);
	/* Ring setting heading */
	wattrset(ui->w_wheels, A_NORMAL);
	mvwprintw(ui->w_wheels, 9+m->wheelslots, 4*m->wheelslots, "ring setting");
}
Beispiel #5
0
/* change the highlighted code wheel */
void next_wheel(machine *m, ui_info *ui) {
	if (ui->chosen_wheel < 0) return;
	wheelslot *sl = &m->slot[ui->chosen_wheel];
	if (sl->type == T_WHEEL) {
		/* Change an ordinary wheel or reflector, to another allowed wheel */
		do {
			sl->w = sl->w->next_in_set;
		} while(!sl->w->allow_slot[ui->chosen_wheel]);
		draw_wheel(m, ui, ui->chosen_wheel);
	} else {
		/* change plugboard- / crossbar-settings, or rewire a wheel */
		wint_t s[m->alphabet_len * 2];
		echo();
		char *err = ""; /* Short msg if they screw up */
		for (bool done = false; !done; ) {
			wclear(ui->w_pop);
			if (sl->type == T_PAIRSWAP) {
				wprintw(ui->w_pop, "%sGive plugboard swaps in the format AX CF ...\nor just enter for the identity mapping\n", err);
				mvwgetn_wstr(ui->w_pop, 2, 0, s, (m->alphabet_len / 2) * 3);
				identity_map(m, sl->w);
				wchar_t *l1=s, *l2;
				done = true; /* optimistic */
				do { /* Each iteration parses one stecker pair */
					while (*l1 == L' ') ++l1;
					if (*l1) { /*  if we didn't hit \0 */
						l2 = l1 + 1;
						int i1 = lookup(*l1, m->alphabet);
						int i2 = lookup(*l2, m->alphabet);
						if (i1 == -1 || i2 == -1) {
							*l1 = 0;
							err = "Letter not in machine alphabet. ";
							done = false;
						} else {
							/* Got a pair, and it is valid! Set up the encoding & decoding */						
							sl->w->encode[i1] = i2;
							sl->w->encode[i2] = i1;
							sl->w->decode[i1] = i2;
							sl->w->decode[i2] = i1;
							l1 = l2 + 1;
						}
					}
				} while (*l1);
			} else {
				wprintw(ui->w_pop, "Type the new mapping like XYZABCDE...\nor just enter for the identity mapping\n");
				mvwgetn_wstr(ui->w_pop, 2, 0, s, m->alphabet_len);
				identity_map(m, sl->w);
				done = true; /* Unless we get a bad string */
				int i = 0;
				wchar_t *l = s;
				while (*l && i < m->alphabet_len && done) {
					int c = lookup(*l, m->alphabet);
					if (c == -1) {
						err = "Letter not in machine alphabet. ";
						done = false;
					} else {
						sl->w->encode[i] = c;
						sl->w->decode[c] = i;
					}
					++i;
					++l;
				}
				/* More sanity checking */
				if (done) {
					if (*l) {
						err = "Too many characters. ";
						done = false;
					} else if (i < m->alphabet_len) {
						err = "Too few characters. ";
						done = false;
					}
				}

			}
		}
		noecho();
		redrawwin(ui->w_code);
		wnoutrefresh(ui->w_code);	

	}
	wnoutrefresh(ui->w_wheels);
	step_cleanup(m);
}