void mesh_geometry::draw_normals(void) { lock(); if(position_get()) { if(flag_get(GEOMETRY_NORMALS_DIRTY)) normals_update(); int i,vertexnum = vertexnum_get(); VECT *p_vert = position_get(); VECT *p_norm = normal_get(); if(p_norm == NULL) return; mesh_material::set_default(); glColor3f(0.0f,0.0f,1.0f); glBegin(GL_LINES); for(i = 0; i < vertexnum; i++) { glVertex3fv((float *)(p_vert+i)); VECT endpoint = p_norm[i]*10.0f; endpoint += p_vert[i]; glVertex3fv((float *)(&endpoint)); } glEnd(); } unlock(); }
VECT * mesh_geometry::size_get(VECT *p_size) { lock(); if(position_get()) { AABB tmp(position_get(),vertexnum_get(),NULL,0); tmp.size_get(p_size); } unlock(); return(p_size); }
void mesh_geometry::transformate(GLMATRIX *p_mt) { lock(LOCK_READ_WRITE); if(position_get()) { int i,vertexnum = vertexnum_get(); VECT *p_vert = position_get(); for(i = 0; i < vertexnum; i++) { p_mt->transformate(p_vert+i); } } unlock(); }
void edit_select_rep::selection_move () { observer pos= position_new (tp); tree t= selection_get_cut (); go_to (position_get (pos)); insert_tree (t); position_delete (pos); }
VECT * mesh_geometry::center_get(VECT *p_center) { lock(); if(position_get()) { int i,vertexnum = vertexnum_get(); VECT *p_vert = position_get(); p_center->set(); for(i = 0; i < vertexnum; i++) { *p_center += p_vert[i]; } *p_center *= (1.0f/(float)(vertexnum)); } unlock(); return(p_center); }
static void worldmap_gainFocus (EntComponent comp, EntSpeech speech) { worldmapData map = component_getData (entity_getAs (Worldmap, "worldmap")); hexPos pos = position_get (entity_getByName ("PLAYER")); map->types = mapDataTypes (hexPos_platter (pos, map->spanFocus)); if (map->types) map->typeFocus = 0; }
void mesh_geometry::normals_update(bool force) { if((force || flag_get(GEOMETRY_NORMALS_DIRTY)) && vertexnum_get() && facenum_get()) { lock(); normals_calc(position_get(),vertexnum_get(), faces_get(),facenum_get(), normal_get()); unlock(); flag_set(GEOMETRY_NORMALS_DIRTY); } }
// ******************************** // Mesh geometry // ******************************** void mesh_geometry::box_update(bool force) { if((force || flag_get(GEOMETRY_BOX_DIRTY)) && vertexnum_get() && facenum_get()) { if(!p_box) { p_box = box_create(box_type); } lock(); p_box->set(position_get(), vertexnum_get(), faces_get(), facenum_get()); unlock(); flag_clear(GEOMETRY_BOX_DIRTY); box_change_set(); } }
static void worldmap_input (EntComponent comp, EntSpeech speech) { Entity this = component_entityAttached (comp); worldmapData map = component_getData (entity_getAs (Worldmap, "worldmap")); struct input_event * input = speech->arg; hexPos pos = position_get (entity_getByName ("PLAYER")); // the span index is backwards compared to usual because i'd like it to maintain the usual span mapping, which is 0 = hex level, MapSpan = pole level - xph 2012 01 17 if (!input->active) return; switch (input->code) { case IR_UI_MENU_INDEX_DOWN: if (map->spanTypeFocus == FOCUS_SPAN && map->spanFocus != 0) { if (map->typeFocus != 0) { textureDestroy (map->spanTextures[map->spanFocus]); map->spanTextures[map->spanFocus] = NULL; } map->spanFocus--; map->types = mapDataTypes (hexPos_platter (pos, map->spanFocus)); if (map->types) map->typeFocus = 0; } else if (map->types && map->typeFocus < (dynarr_size (map->types) - 1)) { map->typeFocus++; if (map->spanTextures[map->spanFocus]) { textureDestroy (map->spanTextures[map->spanFocus]); map->spanTextures[map->spanFocus] = NULL; } } break; case IR_UI_MENU_INDEX_UP: if (map->spanTypeFocus == FOCUS_SPAN && map->spanFocus != map->worldSpan) { if (map->typeFocus != 0) { textureDestroy (map->spanTextures[map->spanFocus]); map->spanTextures[map->spanFocus] = NULL; } map->spanFocus++; map->types = mapDataTypes (hexPos_platter (pos, map->spanFocus)); if (map->types) map->typeFocus = 0; } else if (map->typeFocus != 0) { map->typeFocus--; if (map->spanTextures[map->spanFocus]) { textureDestroy (map->spanTextures[map->spanFocus]); map->spanTextures[map->spanFocus] = NULL; } } break; case IR_UI_MODE_SWITCH: map->spanTypeFocus ^= 1; break; case IR_WORLDMAP_SWITCH: printf ("focusing world\n"); entity_message (this, NULL, "loseFocus", NULL); entity_messageGroup ("PlayerAvatarEntities", NULL, "gainFocus", NULL); break; default: break; } }
static void worldmap_draw (EntComponent comp, EntSpeech speech) { float zNear = video_getZnear () - 0.001; unsigned int width, height; int i = 0, frameMargin = 32, sMargin = 8, sWidth = 55, sHeight = 34, maxWidth, maxHeight, mapSize, mapXMargin, mapYMargin; worldmapData map; const char * type; hexPos position; if (!Worldmap || !input_hasFocus (Worldmap)) return; map = component_getData (entity_getAs (Worldmap, "worldmap")); video_getDimensions (&width, &height); glColor4ub (0xff, 0xff, 0xff, 0xff); glBindTexture (GL_TEXTURE_2D, 0); glBegin (GL_QUADS); i = 0; while (i <= map->worldSpan) { glVertex3f ( video_xMap (width - (frameMargin + sWidth)), video_yMap (i * (sHeight + sMargin) + frameMargin), zNear ); glVertex3f ( video_xMap (width - (frameMargin + sWidth)), video_yMap (i * (sHeight + sMargin) + sHeight + frameMargin), zNear ); glVertex3f ( video_xMap (width - frameMargin), video_yMap (i * (sHeight + sMargin) + sHeight + frameMargin), zNear ); glVertex3f ( video_xMap (width - frameMargin), video_yMap (i * (sHeight + sMargin) + frameMargin), zNear ); i++; } glColor3ub (0xff, 0x00, 0x99); if (map->spanTypeFocus == FOCUS_SPAN) { glVertex3f (video_xMap (width - (frameMargin - 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) + 8), zNear); glVertex3f (video_xMap (width - (frameMargin - 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) - 8), zNear); glVertex3f (video_xMap (width - (frameMargin + 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) - 8), zNear); glVertex3f (video_xMap (width - (frameMargin + 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) + 8), zNear); } else { int fh = fontLineHeight (); glVertex3f (video_xMap (frameMargin - 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) + 8), zNear); glVertex3f (video_xMap (frameMargin + 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) + 8), zNear); glVertex3f (video_xMap (frameMargin + 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) - 8), zNear); glVertex3f (video_xMap (frameMargin - 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) - 8), zNear); } glEnd (); position = position_get (entity_getByName ("PLAYER")); if (map->types != NULL) { i = 0; fontPrintAlign (ALIGN_LEFT); while ((type = *(const char **)dynarr_at (map->types, i++))) { if (i - 1 == map->typeFocus) glColor4ub (0xff, 0xff, 0xff, 0xff); else glColor4ub (0xaf, 0xaf, 0xaf, 0xff); fontPrint (type, frameMargin, frameMargin + fontLineHeight () * (i - 1)); } } if (map->spanTextures[map->spanFocus] == NULL) { printf ("generating map texture for span %d using pos %p\n", map->spanFocus, position); if (map->types) map->spanTextures[map->spanFocus] = mapGenerateMapTexture (position, map->spanFocus, 0, *(const char **)dynarr_at (map->types, map->typeFocus)); else map->spanTextures[map->spanFocus] = mapGenerateMapTexture (position, map->spanFocus, 0, NULL); } glBindTexture (GL_TEXTURE_2D, textureName (map->spanTextures[map->spanFocus])); glColor4ub (0xff, 0xff, 0xff, 0xff); maxWidth = width - (frameMargin * 2 + sWidth + sMargin); maxHeight = height - (frameMargin * 2); mapSize = maxWidth < maxHeight ? maxWidth : maxHeight; mapXMargin = (width - mapSize) / 2; mapYMargin = (height - mapSize) / 2; glBegin (GL_QUADS); glTexCoord2f (0.00, 0.00); glVertex3f (video_xMap (mapXMargin), video_yMap (mapYMargin), zNear); glTexCoord2f (0.00, 1.00); glVertex3f (video_xMap (mapXMargin), video_yMap (mapYMargin + mapSize), zNear); glTexCoord2f (1.00, 1.00); glVertex3f (video_xMap (mapXMargin + mapSize), video_yMap (mapYMargin + mapSize), zNear); glTexCoord2f (1.00, 0.00); glVertex3f (video_xMap (mapXMargin + mapSize), video_yMap (mapYMargin), zNear); glEnd (); glBindTexture (GL_TEXTURE_2D, 0); }