vector3 gl_camera::get_position() const { vector3 p; float t1, t2; float b; p[2] = get_distance(); p[0] = p[1] = 0.0; // rotate about x b = -get_elevation() / 180.0 * PI; t1 = cos(b)*p[1] - sin(b)*p[2]; t2 = sin(b)*p[1] + cos(b)*p[2]; p[1] = t1; p[2] = t2; // rotate about y b = get_twist() / 180.0 * M_PI; t1 = cos(b)*p[0] + sin(b)*p[2]; t2 = -sin(b)*p[0] + cos(b)*p[2]; p[0] = t1; p[2] = t2; // translate p.add(get_focal_point()); return p; }
void martini_glass_fly(int i) { if (full_objects[i].draw == 1) { /* move along the terrain flying above it at a set altitude */ double Rad1 = 50+49.*Cos(2*martini_angle); double Rad2 = 50.0-49.*Cos(2*martini_angle); //float x_z_pos[2]={0,0}; full_objects[i].pos[0] = Rad2*Cos(martini_angle) + quads[full_objects[i].quad[0]][full_objects[i].quad[1]].center[0]; full_objects[i].pos[2] = -Rad1*Cos(martini_angle) + quads[full_objects[i].quad[0]][full_objects[i].quad[1]].center[1]; full_objects[i].pos[1] = get_elevation(full_objects[i].pos[0], full_objects[i].pos[2]) + martini_alt; full_objects[i].rot[2] += 13*martini_angle_rate*(t_now-t_last); full_objects[i].rot[1] = 2*full_objects[i].rot[2]; if (full_objects[i].rot[0]>360) full_objects[i].rot[0] -=360; if (full_objects[i].rot[2]>360) full_objects[i].rot[2] -=360; full_objects[i].area[0]=(int)(full_objects[i].pos[0]+ x_offset)/X_DIM; full_objects[i].area[1]=(int)(full_objects[i].pos[2]+ z_offset)/Z_DIM; /* needed for collision checks since it could be out of its quad of origin * (not quite right, should leave in its own quad, but check collision if it is being drawn and * a martini glass) */ // x_z_pos[0]=full_objects[i].pos[0]; x_z_pos[0]=full_objects[i].pos[2]; //quad_from_pos(x_z_pos,full_objects[i].quad); } }
void Heightfield::set_auto_origin( void ) { mesh_origin[ 0 ] = -mesh_scale[ 0 ] * 0.5f; mesh_origin[ 1 ] = 0.0f; mesh_origin[ 2 ] = -mesh_scale[ 2 ] * 0.5f; float center_elev = get_elevation( 0.0f, 0.0f ); mesh_origin[ 1 ] = -center_elev; dirty_normals = true; }
void Heightfield::load_normals( void ) { if( normal_arr ) { delete [] normal_arr; } normal_arr = new float[ ( image_width - 1 ) * ( image_height - 1 ) * 2 * 3 ]; int norm_index = 0; for( int j = 0; j < mesh_resz - 1; j++ ) { for( int i = 0; i < mesh_resx - 1; i++ ) { int A_index = ( j * mesh_resx + i ) * 3; int B_index = ( ( j + 1 ) * mesh_resx + i ) * 3; int C_index = ( j * mesh_resx + i + 1 ) * 3; calc_normal( normal_arr + norm_index, vertex_arr + A_index, vertex_arr + B_index, vertex_arr + C_index, mesh_scale ); norm_index += 3; A_index = ( j * mesh_resx + i + 1 ) * 3; B_index = ( ( j + 1 ) * mesh_resx + i ) * 3; C_index = ( ( j + 1 ) * mesh_resx + i + 1 ) * 3; calc_normal( normal_arr + norm_index, vertex_arr + A_index, vertex_arr + B_index, vertex_arr + C_index, mesh_scale ); norm_index += 3; } } dirty_normals = false; #if 0 for( int i = 0; i <= 10; i++ ) { // float px = 0.0f; // float px = 1.0f; float px = (float)i/10.0f; // float px = 1.0f - (float)i/10.0f; // float pz = 0.0f; // float pz = 1.0f; float pz = (float)i/10.0f; // float pz = 1.0f - (float)i/10.0f; float n[ 3 ]; float y = get_elevation( px, pz, n ); printf( "%f %f : %f : %f %f %f\n", px, pz, y, n[0], n[1], n[2] ); } #endif }
void place_object(int i) { float obj_normal[3] = {0,1,0}; /* set object's (at least initial) elevation */ if (full_objects[i].type !=7 ) get_normal(full_objects[i].area[0], full_objects[i].area[1], obj_normal); full_objects[i].rot[1] = RADS_TO_DEGS*atan(obj_normal[2]/obj_normal[1]); full_objects[i].rot[2] = -RADS_TO_DEGS*atan(obj_normal[0]/obj_normal[1]); /* set object's (at least initial) pitch and roll on the terrain */ full_objects[i].pos[1] = get_elevation(full_objects[i].pos[0], full_objects[i].pos[2]); }
static PyObject * ossim_height(PyObject *self, PyObject *args) { float lat,lon; // char lat_s[10], lon_s[10]; // char *pref_file; // memset(lat_s, 0, 10); // memset(lon_s, 0, 10); if (!PyArg_ParseTuple(args, "ff", &lat, &lon)) return NULL; // snprintf(lat_s, 10, "%.6f", lat); // snprintf(lon_s, 10, "%.6f", lon); return get_elevation(lat, lon); }
int main() { QFile in_file("europe.car"); QString line, name, temp; bool newobject = false; int type, x, y, low, low_id, high, high_id; int points = 0; int ignore_c = 0; unsigned int count = 0; if(!in_file.open(IO_ReadOnly)) { // warning("KFLog: Can not open airspacefile %s", file); return false; } QTextStream in(&in_file); QList<QString> neu; while(!in.eof()) { line = in.readLine(); neu = split_string(line); if(*neu.at(0) == "H") { y = 0; x = 0; int elev = -1; int id = -1; newobject = true; type = neu.at(1)->toInt(); points = neu.at(2)->toInt(); name = *neu.at(3); switch(type) { case 1: // Luftraum D + F (CTR und nicht) type = 24; break; case 2: // Flugbeschränkungsgebiet (R) type = 32; break; case 3: // Sperrgebiet (P) type = 32; break; case 4: // Gefahrengebiet (D) type = 30; break; case 5: // Tieffluggebiet type = 31; break; case 6: // Luftraum C type = 23; break; case 9: // Kontrollbezirk // wird von uns nicht verwendet type = 100; break; default: break; } //Höhen temp = *neu.at(8); get_elevation(*neu.at(8),&id,&elev); low = elev; low_id = id; get_elevation(*neu.at(9),&id,&elev); high = elev; high_id = id; if(low_id == 2 && low == 0 && type == 22) { // Kontrolzone type = 29; } if(type == 31 && low != 0) { cerr << temp << endl; // cerr << "Ey we've got a real low flying area!!\n"; ignore_c++; } if((low_id == 3 && low >= 100) || type == 100) { newobject = false; ignore_c++; // cerr << "High Level Airspace!! Ignoring... " << temp << " " << ignore_c << endl; } else { cout << "[NEW]\n"; cout << "TYPE=" << type << endl; cout << "LOWER=" << low << endl; cout << "LTYPE=" << low_id << endl; cout << "UPPER=" << high << endl; cout << "UTYPE=" << high_id << endl; cout << "NAME=" << name << endl; } } else if(newobject) { // nun Punkte einlesen x = neu.at(1)->toFloat() * 600000.0; y = neu.at(2)->toFloat() * 600000.0; /* if(y < 0) { y = 0; } if(x < 0) { x = 0; } */ // cout << y << ".00'00\"N" << " " << x << ".00'00\"E" << endl; cout << y << " " << x << endl; count++; if(count == points) { x = 0; y = 0; newobject = false; cout << "[END]\n"; count = 0; } } } cerr << ignore_c << endl; }
void populate_game_quad(int i, int j, unsigned int iseed) { int ii=0; unsigned char success = 1; srand (iseed); int obj = num_objects; int blockers = 0; int num_blockers = 2; float x_tree = 0.0, y_tree=0.0, z_tree = 0.0; /* create evil teapot data */ /* * random initial values: angle for prelim circular motion, scale */ full_objects[obj].type=0; full_objects[obj].rot[0]=((float)(rand()%360)); full_objects[obj].rot[1]=full_objects[obj].rot[2]=0; full_objects[obj].pos[0]=.45*quad_dims[0]*Cos(full_objects[obj].rot[0]-90)+quads[i][j].center[0]; full_objects[obj].pos[1]=0; full_objects[obj].pos[2]=.45*quad_dims[0]*Sin(full_objects[obj].rot[0]-90)+quads[i][j].center[1]; full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=5*(.05*((float)(rand()%11))+.75); full_objects[obj].radius=full_objects[obj].scale[0]*shapes[0].radius; full_objects[obj].draw=1; full_objects[obj].area[0]=(int)(full_objects[obj].pos[0]+ x_offset)/X_DIM; full_objects[obj].area[1]=(int)(full_objects[obj].pos[2]+ z_offset)/Z_DIM; full_objects[obj].quad[0]=i; full_objects[obj].quad[1]=j; full_objects[obj].alpha = 0; full_objects[obj].color = 11; full_objects[obj].texture = ((int)(rand()%8)+1); full_objects[obj].pursuit = 0; full_objects[obj].reward = shapes[0].reward; full_objects[obj].penalty = shapes[0].penalty; quads[i][j].objs_in_quad[quads[i][j].num_objs]=obj; quads[i][j].num_objs+=1; num_objects = obj +=1; /* create prize data */ /* * random initial values: angle of x/z rot, scale, x/z location * and make sure it is created AWAY from Renny in initial QUAD */ full_objects[obj].type=(rand()%4)+1; full_objects[obj].rot[0]=((float)(rand()%360)); full_objects[obj].rot[1]=full_objects[obj].rot[2]=0; full_objects[obj].pos[0]=quad_dims[0]*.05*((float)(rand()%19)+1)+quads[i][j].x_range[0]; full_objects[obj].pos[1]=0; full_objects[obj].pos[2]=quad_dims[1]*.05*((float)(rand()%19)+1)+quads[i][j].z_range[0]; full_objects[obj].area[0]=(int)(full_objects[obj].pos[0]+ x_offset)/X_DIM; full_objects[obj].area[1]=(int)(full_objects[obj].pos[2]+ z_offset)/Z_DIM; /* make sure to avoid Renny's initial position */ if (full_objects[obj].area[0] == i_cntr && full_objects[obj].area[1] == j_cntr) { if (fabs(full_objects[obj].pos[0]-x_offset)<10 && fabs(full_objects[obj].pos[2]-z_offset)<10) { int move_x = rand()%3-1, move_z = rand()%3-1; if (move_x == 0 && move_z == 0) while (move_z == 0) move_z = rand()%3-1; full_objects[obj].pos[0] += move_x*X_DIM; full_objects[obj].pos[2] += move_z*Z_DIM; full_objects[obj].area[0] += move_x; full_objects[obj].area[1] += move_z; } } full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=2.5*(.05*((float)(rand()%11))+.75); full_objects[obj].radius=full_objects[obj].scale[0]*shapes[full_objects[obj].type].radius; full_objects[obj].quad[0]=i; full_objects[obj].quad[1]=j; full_objects[obj].draw=1; full_objects[obj].alpha = 1; full_objects[obj].color = rand()%2; full_objects[obj].texture = -1; full_objects[obj].pursuit = 0; full_objects[obj].reward = shapes[full_objects[obj].type].reward; full_objects[obj].penalty = shapes[full_objects[obj].type].penalty; num_prizes += 1; quads[i][j].objs_in_quad[quads[i][j].num_objs]=obj; quads[i][j].num_objs+=1; num_objects = obj +=1; /* create the two blocking objects data */ /* * random initial values: angle of x/z rot, scale, x/z location which is * within 0.25 of x/z AREA dim of the prize, but at least 3 units away from the prize */ for (blockers = 0; blockers<num_blockers; blockers +=1) { int prize = 1+blockers; full_objects[obj].type=(rand()%4)+1; full_objects[obj].rot[0]=((float)(rand()%360)); full_objects[obj].rot[1]=full_objects[obj].rot[2]=0; full_objects[obj].pos[0]=0.025*X_DIM*((float)(rand()%21)-10); full_objects[obj].pos[1]=0; full_objects[obj].pos[2]=0.025*X_DIM*((float)(rand()%21)-10); /* make sure to avoid prize's position */ if (fabs(full_objects[obj].pos[0])<10 && fabs(full_objects[obj].pos[2])<10) { int move_x = rand()%2; if (move_x) { if (full_objects[obj].pos[0] < 0) full_objects[obj].pos[0] -= 10; else full_objects[obj].pos[0] += 10; } else { if (full_objects[obj].pos[2] < 0) full_objects[obj].pos[2] -= 10; else full_objects[obj].pos[2] += 10; } } /* make sure second blocker not on top of first */ if (blockers == 1) { if (fabs(full_objects[obj].pos[0]-full_objects[obj-1].pos[0])<4 && fabs(full_objects[obj].pos[2]-full_objects[obj-1].pos[2])<4) { int move_x = rand()%2; if (move_x) { if (full_objects[obj].pos[0] < 0) full_objects[obj].pos[0] -= 5; else full_objects[obj].pos[0] += 5; } else { if (full_objects[obj].pos[2] < 0) full_objects[obj].pos[2] -= 5; else full_objects[obj].pos[2] += 5; } } } full_objects[obj].pos[0]+=full_objects[obj-prize].pos[0]; full_objects[obj].pos[2]+=full_objects[obj-prize].pos[2]; full_objects[obj].area[0]=(int)(full_objects[obj].pos[0]+ x_offset)/X_DIM; full_objects[obj].area[1]=(int)(full_objects[obj].pos[2]+ z_offset)/Z_DIM; full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=3*(.05*((float)(rand()%11))+.75); full_objects[obj].radius=full_objects[obj].scale[0]*shapes[full_objects[obj].type].radius; full_objects[obj].draw=1; full_objects[obj].quad[0]=i; full_objects[obj].quad[1]=j; full_objects[obj].alpha = 0; full_objects[obj].color = rand()%9 + 2; full_objects[obj].texture = -1; full_objects[obj].pursuit = 0; full_objects[obj].reward = shapes[full_objects[obj].type].reward; full_objects[obj].penalty = shapes[full_objects[obj].type].penalty; quads[i][j].objs_in_quad[quads[i][j].num_objs]=obj; quads[i][j].num_objs+=1; num_objects = obj +=1; } for (ii=0; ii<4; ii++) { /* draw a few trees, if elev > 100 */ x_tree=quad_dims[0]*.01*((float)(rand()%93)+4)+quads[i][j].x_range[0]; z_tree=quad_dims[1]*.01*((float)(rand()%93)+4)+quads[i][j].z_range[0]; y_tree=get_elevation(x_tree, z_tree); if (y_tree > 100) { #ifdef DEBUG_QUADS printf("quad[%d][%d] has a tree\n", i, j); #endif full_objects[obj].type=7; full_objects[obj].rot[0]=full_objects[obj].rot[1]=full_objects[obj].rot[2]=0; full_objects[obj].pos[0]=x_tree; full_objects[obj].pos[1]=y_tree; full_objects[obj].pos[2]=z_tree; full_objects[obj].area[0]=(int)(full_objects[obj].pos[0]+ x_offset)/X_DIM; full_objects[obj].area[1]=(int)(full_objects[obj].pos[2]+ z_offset)/Z_DIM; full_objects[obj].quad[0]=i; full_objects[obj].quad[1]=j; /* make sure to avoid Renny's initial position */ if (full_objects[obj].area[0] == i_cntr && full_objects[obj].area[1] == j_cntr) { if (fabs(full_objects[obj].pos[0]-x_offset)<15 && fabs(full_objects[obj].pos[2]-z_offset)<15) { int move_x = rand()%3-1, move_z = rand()%3-1; if (move_x == 0 && move_z == 0) while (move_z == 0) move_z = rand()%3-1; full_objects[obj].pos[0] += move_x*X_DIM; full_objects[obj].pos[2] += move_z*Z_DIM; full_objects[obj].area[0] += move_x; full_objects[obj].area[1] += move_z; } } full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=.05*((float)(rand()%11))+.75; full_objects[obj].radius=full_objects[obj].scale[0]*shapes[full_objects[obj].type].radius; full_objects[obj].draw=1; full_objects[obj].alpha = 0; full_objects[obj].color = 255; full_objects[obj].texture = -1; full_objects[obj].pursuit = 0; full_objects[obj].reward = shapes[full_objects[obj].type].reward; full_objects[obj].penalty = shapes[full_objects[obj].type].penalty; quads[i][j].objs_in_quad[quads[i][j].num_objs]=obj; quads[i][j].num_objs+=1; num_trees += 1; num_objects = obj +=1; } } /* create sugar energy cube (if allowed, based on random init, 20% chance) */ /* * random initial values: x/z location which is at least 3 units away from * each blocking object and the prize */ if (rand()%5 == 0) { #ifdef DEBUG_QUADS printf("have energy cube\n"); #endif full_objects[obj].type=6; full_objects[obj].rot[0]=((float)(rand()%360)); full_objects[obj].rot[1]=full_objects[obj].rot[2]=0; full_objects[obj].pos[0]=quad_dims[0]*.05*((float)(rand()%19)+1)+quads[i][j].x_range[0]; full_objects[obj].pos[1]=0; full_objects[obj].pos[2]=quad_dims[0]*.05*((float)(rand()%19)+1)+quads[i][j].z_range[0]; full_objects[obj].area[0]=(int)(full_objects[obj].pos[0]+ x_offset)/X_DIM; full_objects[obj].area[1]=(int)(full_objects[obj].pos[2]+ z_offset)/Z_DIM; full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=3; full_objects[obj].quad[0]=i; full_objects[obj].quad[1]=j; /* make sure to avoid Renny's initial position */ if (full_objects[obj].area[0] == i_cntr && full_objects[obj].area[1] == j_cntr) { if (fabs(full_objects[obj].pos[0]-x_offset)<15 && fabs(full_objects[obj].pos[2]-z_offset)<15) { int move_x = rand()%3-1, move_z = rand()%3-1; if (move_x == 0 && move_z == 0) while (move_z == 0) move_z = rand()%3-1; full_objects[obj].pos[0] += move_x*X_DIM; full_objects[obj].pos[2] += move_z*Z_DIM; full_objects[obj].area[0] += move_x; full_objects[obj].area[1] += move_z; } } full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=2.0; //.05*((float)(rand()%11))+.75; full_objects[obj].radius=full_objects[obj].scale[0]*shapes[full_objects[obj].type].radius; full_objects[obj].draw=1; full_objects[obj].alpha = 1; full_objects[obj].color = 11; full_objects[obj].texture = -1; full_objects[obj].pursuit = 0; full_objects[obj].reward = shapes[full_objects[obj].type].reward; full_objects[obj].penalty = shapes[full_objects[obj].type].penalty; quads[i][j].objs_in_quad[quads[i][j].num_objs]=obj; quads[i][j].num_objs+=1; num_cubes += 1; num_objects = obj +=1; } /* create flying martini glasses (if allowed, based on random init, 40% chance) */ /* centered over the quad */ if (rand()%5 < 2) { #ifdef DEBUG_QUADS printf("have glass\n"); #endif full_objects[obj].type=5; full_objects[obj].rot[0]=((float)(rand()%360)); full_objects[obj].rot[1]=((float)(rand()%180)); full_objects[obj].rot[2]=((float)(rand()%180)); full_objects[obj].pos[0]=quads[i][j].center[0]; full_objects[obj].pos[1]=martini_alt; full_objects[obj].pos[2]=quads[i][j].center[1]; full_objects[obj].area[0]=(int)(full_objects[obj].pos[0]+ x_offset)/X_DIM; full_objects[obj].area[1]=(int)(full_objects[obj].pos[2]+ z_offset)/Z_DIM; full_objects[obj].quad[0]=i; full_objects[obj].quad[1]=j; full_objects[obj].scale[0]=full_objects[obj].scale[1]= full_objects[obj].scale[2]=2.5*(.05*((float)(rand()%11))+.75); full_objects[obj].radius=full_objects[obj].scale[0]*shapes[full_objects[obj].type].radius; full_objects[obj].draw=1; full_objects[obj].alpha = 1; full_objects[obj].color = rand()%2; full_objects[obj].texture = -1; full_objects[obj].pursuit = 0; full_objects[obj].reward = shapes[5].reward; full_objects[obj].penalty = shapes[5].penalty; quads[i][j].objs_in_quad[quads[i][j].num_objs]=obj; quads[i][j].num_objs+=1; num_objects = obj +=1; } #ifdef DEBUG_QUADS for (i=0; i<num_objects; i+=1) { printf("%d: %d, %.1f,%.1f,%.1f, %.1f,%.1f,%.1f, %.1f,%.1f,%.1f, %d,%d, %.1f, %d, %d, %d, %d, %d, %d, %d\n", i, full_objects[i].type, full_objects[i].pos[0], full_objects[i].pos[1], full_objects[i].pos[2], full_objects[i].rot[0], full_objects[i].rot[1], full_objects[i].rot[2], full_objects[i].scale[0], full_objects[i].scale[1], full_objects[i].scale[2], full_objects[i].area[0], full_objects[i].area[1], full_objects[i].radius,full_objects[i].draw, full_objects[i].alpha, full_objects[i].color, full_objects[i].texture, full_objects[i].pursuit, full_objects[i].reward, full_objects[i].penalty); } #endif /* check that all is good on quad */ if (success == 1) quads[i][j].populated = 1; }