void MpView::DefaultViewForScene (MpViewGraphData *G) { if (!G) return; Scene& S = G->DS().S; // calculate bounding box float x1,x2,y1,y2,z1,z2; S.Extent(x1,x2,y1,y2,z1,z2); // view box ratios x:y:z const float f = 0.5; // scale factor G->vby = f*(x2-x1); // note ordering (y-z-x) - the internal coordinate system G->vbz = f*(y2-y1); G->vbx = f*(z2-z1); // choose an initial viewpoint depending on extent of scene // look to the center of the scene float cx = (x1+x2)/2, cy = (y1+y2)/2, cz = (z1+z2)/2, r = 1.7 * hypot(x1-x2,y1-y2,z1-z2); S.Look(Vector3D(cx+r,cy+r,cz+r), // define camera position Vector3D(-r,-r,-r), // the look direction FieldOfView(23)); // and the view angle fov // set transformation matrix and fov angle G->viewtrafo = S.GetMatrix(); G->fov = S.GetFieldOfView(); }
Level::Level(Table<PSquare> s, Model* m, vector<Location*> l, const string& message, const string& n, Table<CoverInfo> covers) : squares(std::move(s)), locations(l), model(m), entryMessage(message), name(n), coverInfo(std::move(covers)), bucketMap(squares.getBounds().getW(), squares.getBounds().getH(), FieldOfView::sightRange), lightAmount(squares.getBounds(), 0) { for (Vec2 pos : squares.getBounds()) { squares[pos]->setLevel(this); Optional<pair<StairDirection, StairKey>> link = squares[pos]->getLandingLink(); if (link) landingSquares[*link].push_back(pos); } for (Location *l : locations) l->setLevel(this); for (Vision* vision : Vision::getAll()) fieldOfView.emplace(vision, FieldOfView(squares, vision)); for (Vec2 pos : squares.getBounds()) addLightSource(pos, squares[pos]->getLightEmission(), 1); }
Level::Level(Table<PSquare> s, Model* m, vector<Location*> l, const string& message, const string& n, Table<CoverInfo> covers, int id) : squares(std::move(s)), oldSquares(squares.getBounds()), locations(l), model(m), entryMessage(message), name(n), coverInfo(std::move(covers)), bucketMap(squares.getBounds().getW(), squares.getBounds().getH(), FieldOfView::sightRange), lightAmount(squares.getBounds(), 0), lightCapAmount(squares.getBounds(), 1), levelId(id) { for (Vec2 pos : squares.getBounds()) { squares[pos]->setLevel(this); optional<StairKey> link = squares[pos]->getLandingLink(); if (link) landingSquares[*link].push_back(Position(pos, this)); } for (Location *l : locations) l->setLevel(this); for (VisionId vision : ENUM_ALL(VisionId)) fieldOfView[vision] = FieldOfView(squares, vision); for (Vec2 pos : squares.getBounds()) addLightSource(pos, squares[pos]->getLightEmission(), 1); updateSunlightMovement(); }
void FieldPlot (Scene& scene, int n, Vertex* field, float len, int mode, const char* title, const char* xtitle, const char* ytitle, const char* ztitle, MpAxis* A) // // Draw a 3-component vector field given in 3D space. The field is expected // in an array field[1..n] with n components Vertex(x,y,z,nx,ny,nz) giving // the space point (x,y,z) and the vector field components (nx,ny,nz). // { int i; float x1,x2,y1,y2,z1,z2,nx1,nx2,ny1,ny2,nz1,nz2, d,x,y,z,dx,dy,dz,dist; Vector3D camera,look; Vertex *v; int axis,scale; if (! scene.IsOpen()) Matpack.Error(Mat::UnspecifiedError,"FieldPlot: scene is not open"); // defines the arrow float headlength = 0.4, headthick = 0.4, thick = 0.2; // evaluate flags axis = ! (mode & NoAxis); scale = ! (mode & NoAutoScale); // find extremal coordinates x1..x2, y1..y2, z1..z2 // and vector field values nx1..nx2, ny1..ny2, nz1..nz2 v = &field[1]; x1 = x2 = v->x; y1 = y2 = v->y; z1 = z2 = v->z; nx1 = nx2 = v->nx; ny1 = ny2 = v->ny; nz1 = nz2 = v->nz; for (i = 2, v++; i <= n; i++, v++) { if (v->x < x1) x1 = v->x; else if (v->x > x2) x2 = v->x; if (v->y < y1) y1 = v->y; else if (v->y > y2) y2 = v->y; if (v->z < z1) z1 = v->z; else if (v->z > z2) z2 = v->z; if (v->nx < nx1) nx1 = v->nx; else if (v->nx > nx2) nx2 = v->nx; if (v->ny < ny1) ny1 = v->ny; else if (v->ny > ny2) ny2 = v->ny; if (v->nz < nz1) nz1 = v->nz; else if (v->nz > nz2) nz2 = v->nz; } // compute automatic scale if (scale) { dist = 1; d = x2-x1; camera.x = x1 - dist * d; d = y2-y1; camera.y = y1 - 1.3 * dist * d; // BAD ORDER ????!!! d = z2-z1; camera.z = z2 + 1.8 * dist * d; look.x = 0.5*(x2+x1)-camera.x; look.y = 0.5*(z2+z1)-camera.z; // BAD ORDER ????!!! look.z = 0.5*(y2+y1)-camera.y; scene.Look(camera,look,FieldOfView(30)); } // draw field for (i = 1; i <= n; i++) { v = &field[i]; x = v->x; y = v->y; z = v->z; dx = 0.5 * v->nx * len; dy = 0.5 * v->ny * len; dz = 0.5 * v->nz * len; scene.Arrow(x-dx,z-dz,y-dy, x+dx,z+dz,y+dy, thick,headthick,headlength); } // draw axisframe and titles if (axis) { // not yet } }