public static Vec comb(double a, Vec A, double b, Vec B) { return new Vec(a * A.x + b * B.x, a * A.y + b * B.y, a * A.z + b * B.z); }
public static Vec cross(Vec a, Vec b) { return new Vec(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); }
public void Set(Prec t, Vec n, Material mat) { RayT = t; Point = Ray.Origin + Ray.Direction * t; Normal = n; Material = mat; }
public override Vec normal(Vec p) { Vec r; r = Vec.sub(p, c); r.normalize(); return r; }
public Mouse(MouseButton.EventClick onClickLeft, MouseButton.EventDrag onDragLeft, MouseButton.EventClick onClickRight, MouseButton.EventDrag onDragRight) { mLeft = new MouseButton(onClickLeft, onDragLeft); mRight = new MouseButton(onClickRight, onDragRight); mPos = new Vec(0, 0); }
Vec v, b; // temporary vecs used to minimize the memory load public Sphere(Vec center, double radius) { c = center; r = radius; r2 = r * r; v = new Vec(); b = new Vec(); }
public View(Vec from, Vec at, Vec up, double dist, double angle, double aspect) { this.from = from; this.at = at; this.up = up; this.dist = dist; this.angle = angle; this.aspect = aspect; }
public Surface() { color = new Vec(1, 0, 0); kd = 1.0; ks = 0.0; shine = 0.0; kt = 0.0; ior = 1.0; }
public void drawExplose(Pen pen, Vec pos, double size, double proc) { const int DIR = 24; for (int i = 0; i < DIR; i++) { Vec dir = Vec.getDir(i, DIR, size); Vec p1 = dir * (0.8f + proc * 2); Vec p2 = dir * (1.2f + proc * 2); drawLine(pen, pos + p1, pos + p2); } }
static double ray_trace(Vec light, Ray ray, Scene scene) { Hit i = scene.intersect(new Hit(infinity, new Vec(0, 0, 0)), ray); if (i.lambda == infinity) return 0; Vec o = add(ray.orig, add(scale(i.lambda, ray.dir), scale(delta, i.normal))); double g = dot(i.normal, light); if (g >= 0) return 0.0; Ray sray = new Ray(o, scale(-1, light)); Hit si = scene.intersect(new Hit(infinity, new Vec(0, 0, 0)), sray); return (si.lambda == infinity ? -g : 0); }
public void up(MouseEventArgs e) { mPos = new Vec(e.X, e.Y); switch (e.Button) { case MouseButtons.Left: mLeft.up(mPos); break; case MouseButtons.Right: mRight.up(mPos); break; } }
internal void up(Vec pos) { if (mState == State.Drag) { mDragRezult.mEventDetach(pos); mDragRezult = null; } if (mState == State.Down || mState == State.NoDrag) { if (mOnClick != null) mOnClick(pos); } mState = State.None; }
static Scene create(int level, Vec c, double r) { Sphere sphere = new Sphere(c, r); if (level == 1) return sphere; Group group = new Group(new Sphere(c, 3*r)); group.objs.Add(sphere); double rn = 3*r/Math.Sqrt(12); for (int dz=-1; dz<=1; dz+=2) for (int dx=-1; dx<=1; dx+=2) { Vec c2 = new Vec(c.x+dx*rn, c.y+rn, c.z+dz*rn); group.objs.Add(create(level-1, c2, r/2)); } return group; }
static void run(int n, int level, int ss) { Scene scene = create(level, new Vec(0, -1, 0), 1); System.Console.Write("P5\n"+n+" "+n+"\n255\n"); for (int y=n-1; y>=0; --y) for (int x=0; x<n; ++x) { double g=0; for (int dx=0; dx<ss; ++dx) for (int dy=0; dy<ss; ++dy) { Vec d = new Vec(x+dx*1.0/ss-n/2.0, y+dy*1.0/ss-n/2.0, n); Ray ray = new Ray(new Vec(0, 0, -4), unitise(d)); g += ray_trace(unitise(new Vec(-1, -3, 2)), ray, scene); } System.Console.Write((char)(.5+255*g/(ss*ss))); } }
/// <summary> /// Creates a new instance of the <see cref="OutSimPack"/> class. /// </summary> /// <param name="buffer">A buffer containing the packet data.</param> public OutSimPack(byte[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } PacketReader reader = new PacketReader(buffer); Time = TimeSpan.FromMilliseconds(reader.ReadUInt32()); AngVel = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Heading = reader.ReadSingle(); Pitch = reader.ReadSingle(); Roll = reader.ReadSingle(); Accel = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vel = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Pos = new Vec(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); if (buffer.Length == MaxSize) { ID = reader.ReadInt32(); } }
static double ray_trace(double x, double y, double z, double ox, double oy, double oz, double dx, double dy, double dz) { Vec light = new Vec(x,y,z); Ray ray = new Ray(new Vec(ox,oy,oz), new Vec(dx,dy,dz)); Scene scene = create(3, new Vec(0, -1, 0), 1); double delta=1.4901161193847656E-8; double infinity=Double.PositiveInfinity; Hit i = scene.intersect(new Hit(infinity, new Vec(0, 0, 0)), ray); if (i.lambda == infinity) return 0; Vec o = add(ray.orig, add(scale(i.lambda, ray.dir), scale(delta, i.normal))); double g = dot(i.normal, light); if (g >= 0) return 0.0; Ray sray = new Ray(o, scale(-1, light)); Hit si = scene.intersect(new Hit(infinity, new Vec(0, 0, 0)), sray); return (si.lambda == infinity ? -g : 0); }
static Scene create(int level, Vec c, double r) { Sphere sphere = new Sphere(c, r); if (level == 1) return sphere; Group group = new Group(new Sphere(c, 3*r)); group.obj0 = sphere; double rn = 3*r/Math.Sqrt(12); for (int dz=-1; dz<=1; dz+=2) for (int dx=-1; dx<=1; dx+=2) { Vec c2 = new Vec(c.x+dx*rn, c.y+rn, c.z+dz*rn); switch(1+(dz+1)+(dx+1)/2) { case 1: group.obj1 = create(level-1, c2, r/2); break; case 2: group.obj2 = create(level-1, c2, r/2); break; case 3: group.obj3 = create(level-1, c2, r/2); break; case 4: group.obj4 = create(level-1, c2, r/2); break; } //group.objs[1+(dz+1)+(dx+1)/2] = create(level-1, c2, r/2); } return group; }
internal void move(Vec pos) { switch (mState) { case State.Down: if (mOnDrag != null) { mDragRezult = mOnDrag(pos); if (mDragRezult == null) { mState = State.NoDrag; } else { mState = State.Drag; } } break; case State.Drag: mDragRezult.mEventMove(pos); break; } }
public bool TryFindOpenTileWithin(Vec startPos, int minRadius, int maxRadius, out Vec pos) { // find all possible tiles List <Vec> positions = new List <Vec>(); Rect bounds = new Rect(startPos - (Vec.One * maxRadius), Vec.One * (maxRadius + maxRadius + 1)); foreach (Vec tryPos in bounds) { // skip if out of bounds if (!Bounds.Contains(tryPos)) { continue; } // skip if outside the valid radii int distanceSquared = (tryPos - startPos).LengthSquared; if ((distanceSquared < minRadius) || (distanceSquared > maxRadius)) { continue; } // skip if not open if (!Tiles[tryPos].IsPassable) { continue; } // skip if already an entity there if (mEntities.GetAt(tryPos) != null) { continue; } // if we got here, we found one positions.Add(tryPos); } // bail if there are none pos = startPos; if (positions.Count == 0) { return(false); } // choose one randomly pos = Rng.Item(positions); return(true); }
public Node(Transform point) { this.cellId = -1; this.position = default(Vec); this.point = point; }
public static IEnumerable <Vec> GetPassableNeighbours(State state, Vec initialLocation) { return(GetIncidentPoints(initialLocation) .Where(p => p.InArea(state.Size) && state.CanMove(initialLocation, p))); }
public CellDto GetCell(Vec vector, params string[] type) => Map.FirstOrDefault(x => x.Pos.Equals(vector) && (type == null || type.Contains(x.Type)));
/// <summary> /// The signed height of the supplied point over the plane. /// </summary> public double Height(V2d p) => Vec.Dot(Normal, p) - Distance;
public Refl_t refl; // reflection type (DIFFuse,SPECular,REFRactive) public Sphere(double rad_, Vec p_, Vec e_, Vec c_, Refl_t refl_) { rad = rad_; p = p_; e = e_; c = c_; refl = refl_; }
public Ray(Vec o_, Vec d_) { o = o_; d = d_; }
public double dot(Vec b) { return(x * b.x + y * b.y + z * b.z); }
public Vec mult(Vec b) { return(new Vec(x * b.x, y * b.y, z * b.z)); }
public static void Main(string[] args) { DateTime start = DateTime.Now; // set up image int w = 256, h = 256; int samps = args.Length == 2 ? int.Parse(args[1]) / 4 : 25;// # samples // set up camera Ray cam = new Ray(new Vec(50, 52, 295.6), new Vec(0, -0.042612, -1).norm()); //cam pos,dir // x direction increment (uses implicit 0 for y, z) // Assume upright camera // 0.5135 defines FOV Vec cx = new Vec(w * .5135 / h, 0, 0); // horizontal camera vector direction // cross product gets vector perpendicular to both cx and gaze direction Vec cy = (cx % cam.d).norm() * .5135; // vertical camera direction Vec r; // used for colors of samples Vec[] c = new Vec[w * h]; // the image // creat image by looping over all image pixels for (int y = 0; y < h; y++) { Console.Write("\rRendering ({0}spp) {1:F2}%", samps * 4, 100.0 * y / (h - 1)); // print progress for (int x = 0; x < w; x++) // Loop cols { // for each pixel do 2X2 subsamples, and samps samples per subsample. The subpixel color will be averaged // calculate array index for (x, y): i=(h-y-1)*w+x for (int sy = 0, i = (h - y - 1) * w + x; sy < 2; sy++) // 2x2 subpixel rows { for (int sx = 0; sx < 2; sx++) // 2x2 subpixel cols { r = new Vec(); for (int s = 0; s < samps; s++) { // r1 and r2 are random values of a tent filter // Determine location of sample within pixel double r1 = 2 * erand48(), dx = r1 < 1 ? Math.Sqrt(r1) - 1 : 1 - Math.Sqrt(2 - r1); double r2 = 2 * erand48(), dy = r2 < 1 ? Math.Sqrt(r2) - 1 : 1 - Math.Sqrt(2 - r2); // compute ray direction Vec d = cx * (((sx + .5 + dx) / 2 + x) / w - .5) + cy * (((sy + .5 + dy) / 2 + y) / h - .5) + cam.d; r = r + radiance(new Ray(cam.o + d * 140, d.norm()), 0) * (1.0 / samps); // estimate radiance } // Camera rays are pushed ^^^^^ forward to start in interior // add the gamma-corrected subpixel color estimate to the Pixel color c[i] c[i] = c[i] + new Vec(clamp(r.x), clamp(r.y), clamp(r.z)) * .25; } } } } Console.WriteLine("\n{0} sec", (DateTime.Now - start).TotalSeconds); using (StreamWriter sw = new StreamWriter("image.ppm")) { sw.Write("P3\r\n{0} {1}\r\n{2}\r\n", w, h, 255); for (int i = 0; i < w * h; i++) { sw.Write("{0} {1} {2}\r\n", toInt(c[i].x), toInt(c[i].y), toInt(c[i].z)); } sw.Close(); } }
// compute the radiance estimate along ray // return value - Vec the radiance estimate // r - the ray we are casting // depth - the ray depth // Xi - random number seed // E - whether to include emissive color static Vec radiance(Ray r, int depth) { double t = 0; // distance to intersection int id = 0; // id of intersected object if (!intersect(r, ref t, ref id)) { return(new Vec()); // if miss,return black } Sphere obj = spheres[id]; // the hit object // surface properties Vec x = r.o + r.d * t; // ray intersection point Vec n = (x - obj.p).norm(); // sphere normal Vec nl = n.dot(r.d) < 0 ? n : n * -1; // property oriented surface normal - for refractions Vec f = obj.c; // object color (BRDF modulator) // use maximum reflectivity amount for Russian Roulette double p = f.x > f.y && f.x > f.z ? f.x : f.y > f.z ? f.y : f.z; // use the maximum component (r,g,b) of the surface color. if (++depth > 5) { if (erand48() < p) { f = f * (1 / p); } else { return(obj.e); // Russian Roulette } } if (depth > 100) { return(obj.e); } // Ideal diffuse reflection if (obj.refl == Refl_t.DIFF) { double r1 = 2 * Math.PI * erand48(), r2 = erand48(); // angle around double r2s = Math.Sqrt(r2); // distance from center Vec w = nl; // w = normals Vec u = ((Math.Abs(w.x) > .1 ? new Vec(0, 1, 0) : new Vec(1, 0, 0)) % w).norm(); Vec v = w % u; // v is perpendicular to u and w // sampling unit hemisphere Vec d = (u * Math.Cos(r1) * r2s + v * Math.Sin(r1) * r2s + w * Math.Sqrt(1 - r2)).norm(); // d is random reflection ray return(obj.e + f.mult(radiance(new Ray(x, d), depth))); } else if (obj.refl == Refl_t.SPEC) // Ideal SPECULAR reflection { return(obj.e + f.mult(radiance(new Ray(x, r.d - n * 2 * n.dot(r.d)), depth))); } Ray reflRay = new Ray(x, r.d - n * 2 * n.dot(r.d)); // IdealdielectricREFRACTION bool into = n.dot(nl) > 0; // Ray from outside going in? double nc = 1, nt = 1.5, nnt = into ? nc / nt : nt / nc, ddn = r.d.dot(nl), cos2t; if ((cos2t = 1 - nnt * nnt * (1 - ddn * ddn)) < 0) // Total internal reflection { return(obj.e + f.mult(radiance(reflRay, depth))); } // otherwise choose reflection or refraction Vec tdir = (r.d * nnt - n * ((into ? 1 : -1) * (ddn * nnt + Math.Sqrt(cos2t)))).norm(); double a = nt - nc, b = nt + nc, R0 = a * a / (b * b), c = 1 - (into ? -ddn : tdir.dot(n)); double Re = R0 + (1 - R0) * c * c * c * c * c, Tr = 1 - Re, P = .25 + .5 * Re, RP = Re / P, TP = Tr / (1 - P); return(obj.e + f.mult(depth > 2 ? (erand48() < P ? // Russian roulette radiance(reflRay, depth) * RP : radiance(new Ray(x, tdir), depth) * TP) : radiance(reflRay, depth) * Re + radiance(new Ray(x, tdir), depth) * Tr)); }
public static T First <N, T>(this Vec <S <N>, T> vec) { return(((Cons <N, T>)vec).Head); }
public void AddDoor(Vec pos) { mFactory.PlaceDoor(pos); }
static Vec sub(Vec a, Vec b) { return new Vec(a.x-b.x, a.y-b.y, a.z-b.z); }
/// <summary> /// Creates plane from point and normal vector. IMPORTANT: The /// supplied vector has to be normalized in order for all methods /// to work correctly, however if only relative height computations /// using the <see cref="Height"/> method are necessary, the normal /// vector need not be normalized. /// </summary> public Plane2d(V2d normalizedNormal, V2d point) { Normal = normalizedNormal; Distance = Vec.Dot(normalizedNormal, point); }
internal Vec PxToTile(Vec mousePos) => new Vec(mousePos.X / _fontX, mousePos.Y / _fontY) + RelToAbs;
public ExplainedScore Evaluate(State state, int playerIndex, Vec movedCellLocation) { return(GetDoublecheckedVoronoiScore(state, playerIndex, GetVoronoiAreasCount)); }
public void OnMouseWheel(Vec delta, EventFlags flags) { }
public void Update(Vec position, int cellId) { this.position = position; this.cellId = cellId; }
DragRezult dragFishka(Vec pos) { return mPlayer.getFishkaDragger(mSelectedFishka, pos); }
public FireAction(Hero hero, Vec target) : base(hero) { mTarget = target; }
void onClickRight(Vec pos) { if (mSelectedNode != null) mPlayer.clickNode(mSelectedNode); else if (mSelectedLine != null) mPlayer.clickLine(mSelectedLine); }
public UIElement MakeVectorElement(string name, Vec value, object CurrentObject, int?fixNameWidth) { var g = MakeDefaultGrid(fixNameWidth); var sp = SetCP(2, new WrapPanel() { Orientation = Orientation.Horizontal }); g.Children.Add(sp); //Murdering Code Duplication since 2019 void mktb(string text, double v, Action <double> apply) { var gr = new StackPanel() { Orientation = Orientation.Horizontal }; var block = new TextBlock() { Text = text, Foreground = white, Margin = new Thickness(3, 2, 3, 2) }; gr.Children.Add(block); var box = new TextBox() { Text = v.ToString(), Style = TBStyle }; box.TextChanged += (obj, _) => { var tb = obj as TextBox; if (double.TryParse(tb.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out var res)) { apply(res); UpdateCurrentObject(name, value, CurrentObject); OnChanges(); } else if (tb.Text.Trim().Length == 0) { if (tb.Text.Length != 0) { tb.Text = ""; } } else if (tb.Text == "-") { return; } else { tb.Text = "0"; } }; gr.Children.Add(box); sp.Children.Add(gr); } g.Children.Add(MakeDefaultTextBlock(name)); mktb("X", value.x, (res) => value.x = res); mktb("Y", value.y, (res) => value.y = res); mktb("Z", value.z, (res) => value.z = res); return(g); }
//-------------------------------------------------------------------------------------------------- public void Translate(Vec vec) { Position = Position.Translated(vec); }
public abstract void setCenter(Vec c);
private VecStorage(IRefCounted?memorySource, Vec vec) { _memorySource = memorySource; Vec = vec; }
/// <summary> /// Returns if two vectors are equal. /// </summary> /// <param name="other">The vector to check for equality.</param> /// <returns>True if the vectors are equal.</returns> public bool Equals(Vec other) { return this == other; }
TileGlyph ChooseGlyph(Level map, Vec pos) { var tile = map.GetTile(pos); var glyph = tile.Glyph; switch (glyph.Method) { case TileGlyph.TERRAIN: { var l = map.IsSameTile(pos, pos + new Vec(-1, 0)); var r = map.IsSameTile(pos, pos + new Vec(1, 0)); if (l && r) { glyph.X += 2; } if (l && !r) { glyph.X += 3; } if (!l && r) { glyph.X += 1; } var t = map.IsSameTile(pos, pos + new Vec(0, -1)); var b = map.IsSameTile(pos, pos + new Vec(0, 1)); if (t && b) { glyph.Y += 2; } if (t && !b) { glyph.Y += 3; } if (!t && b) { glyph.Y += 1; } break; } case TileGlyph.WALL: { Vec[] dir8 = { new Vec(-1, -1), new Vec(-1, 0), new Vec(-1, 1), new Vec(0, 1), new Vec(1, 1), new Vec(1, 0), new Vec(1, -1), new Vec(0, -1) }; var g = dir8.Select(d => map.IsSameTile(pos, pos + d)).ToArray(); var t = g[7] && !(g[1] && g[0] && g[6] & g[5]); var b = g[3] && !(g[1] && g[2] && g[4] & g[5]); var l = g[1] && !(g[7] && g[0] && g[2] & g[3]); var r = g[5] && !(g[7] && g[6] && g[4] & g[3]); if (l && r) { glyph.X += 2; } if (l && !r) { glyph.X += 3; } if (!l && r) { glyph.X += 1; } if (t && b) { glyph.Y += 2; } if (t && !b) { glyph.Y += 3; } if (!t && b) { glyph.Y += 1; } break; } case TileGlyph.PIT: { Vec[] dir5 = { new Vec(-1, 0), new Vec(-1, -1), new Vec(0, -1), new Vec(1, -1), new Vec(1, 0) }; var g = dir5.Select(d => map.IsSameTile(pos, pos + d)).ToArray(); var t = g[2]; var l = g[0]; var r = g[4]; if (l && r) { glyph.X += 2; } if (l && !r) { glyph.X += 3; } if (!l && r) { glyph.X += 1; } if (t) { glyph.Y += 1; } break; } default: break; } return(glyph); }
static Vec unitise(Vec a) { return scale(1 / Math.Sqrt(dot(a, a)), a); }
IEnumerable <KeyValuePair <IBlock, Vec> > GetBlocksFrom(Vec pos) { return(BlocksToPos.Where(block => block.Value.Equals(pos))); }
public void move(MouseEventArgs e) { mPos = new Vec(e.X, e.Y); mLeft.move(mPos); mRight.move(mPos); }
/// <summary> /// if zero, point is located on cone /// </summary> public double GetDistance(V3d point) => Vec.Distance(point, GetClosestPoint(point));
DragRezult onDragLeft(Vec pos) { if (mSelectedNode != null) return dragNode(pos); else if (mSelectedFishka != null) return dragFishka(pos); else return null; }
private bool MakeJunction(Connector connector) { // create a random junction Vec center = connector.Position + connector.Direction; bool left = false; bool right = false; bool straight = false; int choice = Rng.Int(100); if (choice < mWriter.Options.ChanceOfTurn) { if (Rng.OneIn(2)) { left = true; } else { right = true; } } else if (choice - mWriter.Options.ChanceOfTurn < mWriter.Options.ChanceOfFork) { if (Rng.OneIn(2)) { left = true; } else { right = true; } straight = true; } else if (choice - mWriter.Options.ChanceOfTurn - mWriter.Options.ChanceOfFork < mWriter.Options.ChanceOfTee) { left = true; right = true; } else if (choice - mWriter.Options.ChanceOfTurn - mWriter.Options.ChanceOfFork - mWriter.Options.ChanceOfTee < mWriter.Options.ChanceOfFourWay) { left = true; right = true; straight = true; } else { straight = true; } // check to see if we can place it Rect rect = new Rect(center.Offset(-1, -1), 3, 3); if (!mWriter.IsOpen(rect, center + connector.Direction.Rotate180)) { return(false); } // place the junction mWriter.SetTile(center, TileType.Floor); // add the connectors if (left) { mWriter.AddRoomConnector(center + connector.Direction.RotateLeft90, connector.Direction.RotateLeft90); } if (right) { mWriter.AddRoomConnector(center + connector.Direction.RotateRight90, connector.Direction.RotateRight90); } if (straight) { mWriter.AddRoomConnector(center + connector.Direction, connector.Direction); } return(true); }
DragRezult dragNode(Vec pos) { return mSelectedNode.getDragger(pos); }
private bool MakeMaze(Connector connector) { // in maze units (i.e. thin walls), not tiles int width = Rng.Int(mWriter.Options.MazeSizeMin, mWriter.Options.MazeSizeMax); int height = Rng.Int(mWriter.Options.MazeSizeMin, mWriter.Options.MazeSizeMax); int tileWidth = width * 2 + 3; int tileHeight = height * 2 + 3; Rect bounds = CreateRectRoom(connector, tileWidth, tileHeight); // bail if we failed if (bounds == Rect.Empty) { return(false); } // the hallway around the maze foreach (Vec pos in bounds.Trace()) { mWriter.SetTile(pos, TileType.Floor); } // sometimes make the walls low if (Rng.OneIn(2)) { foreach (Vec pos in bounds.Inflate(-1)) { mWriter.SetTile(pos, TileType.LowWall); } } // add an opening in one corner Vec doorway; switch (Rng.Int(8)) { case 0: doorway = bounds.TopLeft.Offset(2, 1); break; case 1: doorway = bounds.TopLeft.Offset(1, 2); break; case 2: doorway = bounds.TopRight.Offset(-3, 1); break; case 3: doorway = bounds.TopRight.Offset(-2, 2); break; case 4: doorway = bounds.BottomRight.Offset(-3, -2); break; case 5: doorway = bounds.BottomRight.Offset(-2, -3); break; case 6: doorway = bounds.BottomLeft.Offset(2, -2); break; case 7: doorway = bounds.BottomLeft.Offset(1, -3); break; default: throw new Exception(); } PlaceDoor(doorway); // carve the maze Maze maze = new Maze(width, height); maze.GrowTree(); Vec offset = bounds.Position.Offset(1, 1); maze.Draw(pos => mWriter.SetTile(pos + offset, TileType.Floor)); mWriter.LightRect(bounds, mDepth); // populate it int boostedDepth = mDepth + Rng.Int(mDepth / 5) + 2; Populate(bounds.Inflate(-2), 200, 300, boostedDepth); // place the connectors AddRoomConnectors(connector, bounds); return(true); }
public abstract Vec normal(Vec pnt);
public bool MakeHall(Connector connector) { // create a random hall int length = Rng.Int(mWriter.Options.HallLengthMin, mWriter.Options.HallLengthMax); // check to see if we can place it Rect bounds = Rect.Empty; if (connector.Direction == Direction.N) { bounds = new Rect(connector.Position.X - 1, connector.Position.Y - length, 3, length + 1); } if (connector.Direction == Direction.S) { bounds = new Rect(connector.Position.X - 1, connector.Position.Y, 3, length + 1); } if (connector.Direction == Direction.E) { bounds = new Rect(connector.Position.X, connector.Position.Y - 1, length + 1, 3); } if (connector.Direction == Direction.W) { bounds = new Rect(connector.Position.X - length, connector.Position.Y - 1, length + 1, 3); } if (!mWriter.IsOpen(bounds, null)) { return(false); } // make sure the end corners aren't open unless the position in front of the end is too // prevents cases like: Vec pos = connector.Position + (connector.Direction.Offset * (length + 1)); if (!mWriter.Bounds.Contains(pos)) { return(false); } if (!mWriter.Bounds.Contains(pos + connector.Direction.RotateLeft90)) { return(false); } if (!mWriter.Bounds.Contains(pos + connector.Direction.RotateRight90)) { return(false); } // ####.. // ####.. // ....## <- new hall ends at corner of room // ###### if ((mWriter.GetTile(pos + connector.Direction.RotateLeft90) != TileType.Wall) && (mWriter.GetTile(pos) == TileType.Wall)) { return(false); } if ((mWriter.GetTile(pos + connector.Direction.RotateRight90) != TileType.Wall) && (mWriter.GetTile(pos) == TileType.Wall)) { return(false); } // place the hall pos = connector.Position; for (int i = 0; i <= length; i++) { mWriter.SetTile(pos, TileType.Floor); pos += connector.Direction; } PlaceDoor(connector.Position); PlaceDoor(connector.Position + (connector.Direction.Offset * length)); // add the connectors mWriter.AddHallConnector(connector.Position + (connector.Direction.Offset * length), connector.Direction); Populate(bounds, 10, 10, mDepth); return(true); }
Deg fpdangle(Pt a, Pt b, Vec v) { return (a - b).Normalized().UnsignedAngle(v.Normalized()); }
public void AddDecoration(Vec pos) { mFactory.mWriter.SetTile(pos, mDecoration); }
/// <summary> /// Creates a new camera position packet. /// </summary> /// <param name="buffer">A buffer contaning the packet data.</param> public IS_CPP(byte[] buffer) : this() { PacketReader reader = new PacketReader(buffer); Size = reader.ReadByte(); Type = (PacketType)reader.ReadByte(); ReqI = reader.ReadByte(); reader.Skip(1); Pos = new Vec(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); H = reader.ReadUInt16(); P = reader.ReadUInt16(); R = reader.ReadUInt16(); ViewPLID = reader.ReadByte(); InGameCam = (ViewIndentifier)reader.ReadByte(); FOV = reader.ReadSingle(); Time = TimeSpan.FromMilliseconds(reader.ReadUInt16()); Flags = (StateFlags)reader.ReadUInt16(); }
public void AddInsideRoom(Vec pos) { mInsideRoom(pos); }