bool GLView::scr2world_z0(Vector2<double>& pos, Vector2<int> const& scr) const { push_matrix(); initialize_matrix(); set_perspective_matrix(); double model[16], proj[16]; int view[4]; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); Vector3<double> v; // マウス座標に対応するカメラのznear面上のワールド座標 gluUnProject(GLdouble(scr.x), GLdouble(scr.y), 0.0, model, proj, view, &v.x, &v.y, &v.z); // 透視射影の場合(正射影の場合は単純に(v.x, v.y)) if ((0.0<v.z && v.z<eye_.z) || (eye_.z<v.z && v.z<0.0)) { // 視線の先がz=0平面に交わる場合 double const denom = eye_.z-v.z; pos.set((eye_.z*v.x-v.z*eye_.x)/denom, (eye_.z*v.y-v.z*eye_.y)/denom); pop_matrix(); return true; } else { // 交わらない場合 pos.set(v.x-eye_.x, v.y-eye_.y); pop_matrix(); return false; } }
static void pop_into_lhs(ClmExpNode *node) { // it is an index node - otherwise it is a type check fail char index_str[64]; ClmSymbol *var = clm_scope_find(data.scope, node->indExp.id); switch (var->type) { case CLM_TYPE_INT: load_var_location(var, index_str, 4, NULL); pop_int_into(index_str); break; case CLM_TYPE_FLOAT: load_var_location(var, index_str, 4, NULL); pop_float_into(index_str); break; case CLM_TYPE_MATRIX: pop_matrix(node); break; case CLM_TYPE_STRING: // uhh break; case CLM_TYPE_FUNCTION: // fallthrough case CLM_TYPE_NONE: // shouldn't get here... break; } }
void draw_clock(int x, int y, int w, int h, GR_WINDOW_ID pmap, GR_GC_ID gc, GR_WINDOW_ID window) { int i; GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW)); GrFillRect(pmap, gc, 0, 0, w, h); tick(); push_matrix(); translate(x + w / 2.0 - .5, y + h / 2.0 - .5); scale_xy((w - 1) / 28.0, (h - 1) / 28.0); if (type() == ROUND_CLOCK) { GrSetGCForeground(gc, BLACK); begin_polygon(); circle(0, 0, 14, pmap, gc, w, h); end_polygon(pmap, gc); GrSetGCForeground(gc, BLACK); begin_loop(); circle(0, 0, 14, pmap, gc, w, h); end_loop(pmap, gc); } //draw the shadows push_matrix(); translate(0.60, 0.60); draw_clock_hands(LTGRAY, LTGRAY, pmap, gc); pop_matrix(); //draw the tick marks push_matrix(); GrSetGCForeground(gc, BLACK); for (i = 0; i < 12; i++) { if (6 == i) rect(-0.5, 9, 1, 2, pmap, gc); else if (3 == i || 0 == i || 9 == i) rect(-0.5, 9.5, 1, 1, pmap, gc); else rect(-0.25, 9.5, .5, 1, pmap, gc); rotate(-30); } pop_matrix(); //draw the hands draw_clock_hands(GRAY, BLACK, pmap, gc); pop_matrix(); GrCopyArea(window, gc, 0, 0, w, h, pmap, 0, 0, MWROP_SRCCOPY); }
static void drawhand(double ang, const float v[][2], GR_COLOR fill, GR_COLOR line, GR_WINDOW_ID pmap, GR_GC_ID gc) { int i; push_matrix(); rotate(ang); GrSetGCForeground(gc, fill); begin_polygon(); for (i = 0; i < 4; i++) vertex(v[i][0], v[i][1]); end_polygon(pmap, gc); GrSetGCForeground(gc, line); begin_loop(); for (i = 0; i < 4; i++) vertex(v[i][0], v[i][1]); end_loop(pmap, gc); pop_matrix(); }
static void print_array (void) /*{{{*/ { enum { screen_rows=24, screen_cols=10 }; SLang_Array_Type *at; unsigned int i, num_rows, num_cols; unsigned char type; VOID_STAR v; FILE *fp; int just_one_line; unsigned int num; if (-1 == pop_matrix (&at, &num_rows, &num_cols)) return; type = at->data_type; switch (type) { case SLANG_CHAR_TYPE: case SLANG_UCHAR_TYPE: case SLANG_SHORT_TYPE: case SLANG_USHORT_TYPE: case SLANG_INT_TYPE: case SLANG_UINT_TYPE: case SLANG_LONG_TYPE: case SLANG_ULONG_TYPE: case SLANG_DOUBLE_TYPE: case SLANG_FLOAT_TYPE: case SLANG_COMPLEX_TYPE: break; case SLANG_STRING_TYPE: break; default: SLang_verror (SL_TYPE_MISMATCH, "print_array: %s is not supported", SLclass_get_datatype_name (type)); SLang_free_array (at); return; } fp = NULL; if ((num_rows > screen_rows) || (num_cols > screen_cols)) fp = isis_open_pager (); if (fp == NULL) fp = stdout; v = at->data; just_one_line = 0; num = 0; for (i = 0; i < num_rows; i++) { unsigned int j; for (j = 0; j < num_cols; j++) { int ok; switch (type) { case SLANG_CHAR_TYPE: ok = fprintf (fp, "%d\t", (int)((char *)v)[num]); break; case SLANG_UCHAR_TYPE: ok = fprintf (fp, "%d\t", (int)((unsigned char *)v)[num]); break; case SLANG_SHORT_TYPE: ok = fprintf (fp, "%hd\t", ((short *)v)[num]); break; case SLANG_USHORT_TYPE: ok = fprintf (fp, "%hu\t", ((unsigned short *)v)[num]); break; case SLANG_INT_TYPE: ok = fprintf (fp, "%d\t", ((int *)v)[num]); break; case SLANG_UINT_TYPE: ok = fprintf (fp, "%u\t", ((unsigned int *)v)[num]); break; case SLANG_LONG_TYPE: ok = fprintf (fp, "%ld\t", ((long *)v)[num]); break; case SLANG_ULONG_TYPE: ok = fprintf (fp, "%lu\t", ((unsigned long *)v)[num]); break; case SLANG_FLOAT_TYPE: ok = fprintf (fp, "%e ", ((float *)v)[num]); break; case SLANG_DOUBLE_TYPE: ok = fprintf (fp, "%e ", ((double *)v)[num]); break; case SLANG_STRING_TYPE: ok = fprintf (fp, "\"%s\" ", ((char **)v)[num]); break; case SLANG_COMPLEX_TYPE: ok = fprintf (fp, "(%e, %e) ", ((double *)v)[num], ((double *)v)[num+1]); num++; break; default: ok = -1; } if (ok <= 0) goto done; num++; } if (fputs ("\n", fp) < 0) break; if ((Isis_Batch_Mode == 0) && (fp == stdout) && (((num_rows > screen_rows && (0 == (num_rows % screen_rows))) && (num_rows != 0)) || just_one_line)) { unsigned int key; if (just_one_line == 0) fprintf (stdout, "Press SPACE to continue"); fflush (stdout); key = isis_getkey (); if (key == ' ') just_one_line = 0; else if (key == '\r') just_one_line = 1; else break; } } done: if (fp != stdout) isis_close_pager (fp); fputs ("\n", stdout); SLang_free_array (at); }