public WindowedWall(Point3D from, Point3D to, double bottom, double height, Window window) : base(from, to, bottom, height) { this.ventana = window; Point3D dir = (to - from).Normalized; ventana.Angle = GlUtils.VectorAngle2D(dir); double dist = (to - from).Norm; Point3D d = dir.Scaled((dist - ventana.Width) / 2); izq = new SolidWall(from, from + d, bottom, height); der = new SolidWall(to - d, to, bottom, height); up = new SolidWall(from + d.Scaled(.9), to - d.Scaled(.9), bottom, windowBase); down = new SolidWall(from + d.Scaled(.9), to - d.Scaled(.9), windowBase + this.ventana.Height, (height - windowBase - ventana.Height)); izq.after = to; up.after = to; down.after = to; der.before = from; up.before = from; down.before = from; Point3D wstart = from + d; this.ventana.Location = new Point3D(wstart.X, windowBase, wstart.Z); izq.CloseTo(false); der.CloseFrom(false); up.CloseFrom(false); up.CloseTo(false); down.CloseFrom(false); down.CloseTo(false); }
public Point3D StrafeDir(Point3D direction) { Point3D Xvector = right.Normalized; //camDirection.CrossProduct(up).Normalized; Point3D Yvector = up.Normalized; Point3D Zvector = this.direction.Normalized; //camDirection.Normalized; return(Xvector.Scaled(direction.X) + Yvector.Scaled(direction.Y) + Zvector.Scaled(direction.Z)); }
public Point3D StrafeDir(Point3D direction) { Point3D Xvector = right.Normalized; //mengambil unit vektor Point3D Yvector = up.Normalized; Point3D Zvector = this.direction.Normalized; //scaling return(Xvector.Scaled(direction.X) + Yvector.Scaled(direction.Y) + Zvector.Scaled(direction.Z)); }
public Point3D Rotated(double angle, Point3D axis) { Point3D l = axis.Scaled(this.ScalarProduct(axis)); Point3D r = this - l; if (r.Norm == 0) { return(new Point3D(this)); } double cosBeta = Math.Cos(angle * Math.PI / 180); double sinBeta = Math.Sin(angle * Math.PI / 180); return(l + r.Scaled(cosBeta) + axis.CrossProduct(r).Normalized.Scaled(r.Norm * sinBeta)); }
protected void pintaCristal() { Glu.GLUquadric q = Glu.gluNewQuadric(); Point3D actual = new Point3D(from); Point3D dir = (to - from); double len = dir.Norm; dir = dir.Normalized; Gl.glBindTexture(Gl.GL_TEXTURE_2D, divTexture); Glu.gluQuadricTexture(q, Gl.GL_TRUE); Gl.glColor3d(1, 1, 1); #region Divisiones horizontales double angle = -GlUtils.VectorAngle2D(dir) + 90; for (double d = height; d >= baseHeight; d -= glassvStep) { Gl.glPushMatrix(); Gl.glTranslated(from.X, bottom + d, from.Z); Gl.glRotated(angle, 0, 1, 0); Glu.gluCylinder(q, radius, radius, len, 10, 10); Gl.glPopMatrix(); } #endregion #region Divisiones verticales for (double d = 0; d < len; d += glasshStep) { actual = from + dir.Scaled(d); Gl.glPushMatrix(); Gl.glTranslated(actual.X, actual.Y + baseHeight, actual.Z); Gl.glRotated(-90, 1, 0, 0); Glu.gluCylinder(q, radius, radius, this.height - this.baseHeight, 10, 1); Gl.glPopMatrix(); } actual = to; Gl.glPushMatrix(); Gl.glTranslated(actual.X, actual.Y + baseHeight, actual.Z); Gl.glRotated(-90, 1, 0, 0); Glu.gluCylinder(q, radius, radius, this.height - baseHeight, 10, 1); Gl.glPopMatrix(); Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0); #endregion Glu.gluDeleteQuadric(q); int cullFace = 0; Gl.glGetBooleanv(Gl.GL_CULL_FACE, out cullFace); Gl.glDisable(Gl.GL_CULL_FACE); #region Cristal Gl.glEnable(Gl.GL_BLEND); Gl.glColor4d(.8, .8, 1, .4); Gl.glBegin(Gl.GL_QUADS); Point3D normal = this.planeRot(to - from, -90).Normalized; Gl.glNormal3dv(normal.Coords); Gl.glVertex3dv((from + new Point3D(0, baseHeight, 0)).Coords); Gl.glVertex3dv((to + new Point3D(0, baseHeight, 0)).Coords); Gl.glVertex3dv((to + new Point3D(0, height, 0)).Coords); Gl.glVertex3dv((from + new Point3D(0, height, 0)).Coords); Gl.glEnd(); Gl.glDisable(Gl.GL_BLEND); Gl.glColor3d(1, 1, 1); #endregion if (cullFace != Gl.GL_FALSE) { Gl.glEnable(Gl.GL_CULL_FACE); } }
public override Point3D ColisionNormal(Point3D punto, Point3D direccion, double radius) { Point3D punto2 = punto + direccion; if (punto2.Y < this.bottom || punto2.Y > this.bottom + this.height) { return(new Point3D(0, 0, 0)); } punto2 = new Point3D(punto2.X, 0, punto2.Z); if (((to - from).Norm < radius / 2)) { return(new Point3D(0, 0, 0)); } if ((punto2 - (to - from).Scaled(.5) - from).Norm > (width + radius) / 2) { return(new Point3D(0, 0, 0)); } Point3D walldir = (to - from).Normalized; Point3D exto = to + walldir.Scaled(1.1); Point3D exfrom = from - walldir.Scaled(1.1); Point3D pos = (punto2 - exfrom).Normalized; double d = 0; #region punto2 esta antes o despues de la pared. No hay colision. if (walldir.ScalarProduct(pos) < 0) // El punto esta antes de from { // d=(punto2-frome).Norm; // if (d<radius) // return pos.Scaled(radius-d); // else return(new Point3D(0, 0, 0)); } if ((punto2 - exto).ScalarProduct(-walldir) < 0) // El punto esta despues del to { // d=(punto2-to).Norm; // if (d<radius) // return (punto2-to).Normalized.Scaled(radius-d); // else return(new Point3D(0, 0, 0)); } #endregion Point3D referencia; if ((from - punto2).Norm > (to - punto2).Norm) { referencia = from; } else { referencia = to; } Point3D pr = (to - from).CrossProduct(new Point3D(0, 1, 0)).Normalized; double d1 = this.distancePointRect(punto.X, punto.Z, from.X, from.Z, to.X, to.Z); double d2 = this.distancePointRect(punto2.X, punto2.Z, from.X, from.Z, to.X, to.Z); if (d1 * d2 < 0) { return(pr.Scaled(-Math.Sign(d2) * radius - d2)); } else if (Math.Abs(d2) < radius) { return(pr.Scaled(Math.Sign(d2) * radius - d2)); } return(new Point3D(0, 0, 0)); }
public override Point3D ColisionNormal(Point3D punto, Point3D direccion, double radius) { //Console.WriteLine("Llamando a CN de wall"); Point3D punto2 = punto + direccion; if (punto2.Y < this.bottom || punto2.Y > this.bottom + this.height) { return(new Point3D(0, 0, 0)); //No hay colision } punto2 = new Point3D(punto2.X, 0, punto2.Z); // if ((punto2-from).Norm > width || (punto2-to).Norm>width) // return new Point3D(0,0,0); if (((to - from).Norm < radius / 2)) //La pared es muy pequenna... Ignorare la colision con esta pared. { return(new Point3D(0, 0, 0)); } if ((punto2 - (to - from).Scaled(.5) - from).Norm > (width + radius) / 2) //No puede haber colision { return(new Point3D(0, 0, 0)); } Point3D walldir = (to - from).Normalized; Point3D exto = to + walldir.Scaled(1.1); //radius/2); Point3D exfrom = from - walldir.Scaled(1.1); //radius/2); Point3D pos = (punto2 - exfrom).Normalized; double d = 0; #region punto2 esta antes o despues de la pared. No hay colision. if (walldir.ScalarProduct(pos) < 0) // El punto esta antes de from { // d=(punto2-frome).Norm; // if (d<radius) // return pos.Scaled(radius-d); // else return(new Point3D(0, 0, 0)); } if ((punto2 - exto).ScalarProduct(-walldir) < 0) // El punto esta despues del to { // d=(punto2-to).Norm; // if (d<radius) // return (punto2-to).Normalized.Scaled(radius-d); // else return(new Point3D(0, 0, 0)); } #endregion Point3D referencia; if ((from - punto2).Norm > (to - punto2).Norm) { referencia = from; } else { referencia = to; } Point3D pr = (to - from).CrossProduct(new Point3D(0, 1, 0)).Normalized; double d1 = this.distancePointRect(punto.X, punto.Z, from.X, from.Z, to.X, to.Z); double d2 = this.distancePointRect(punto2.X, punto2.Z, from.X, from.Z, to.X, to.Z); if (d1 * d2 < 0) //semiplanos distintos, hay colision //Console.WriteLine("d1: "+d1+" d2: "+d2); { return(pr.Scaled(-Math.Sign(d2) * radius - d2)); } //return pr.Scaled(radius+d2); //Console.WriteLine("Semiplanos distintos, hay colision"); else if (Math.Abs(d2) < radius) { return(pr.Scaled(Math.Sign(d2) * radius - d2)); } // Point3D pr=this.planeRot(to-from,90).Normalized;; // // Point3D punto1 = new Point3D(punto.X,0,punto.Z); // d=(punto1-referencia).Norm; // Point3D v2 = pr.Scaled(d*pr.ScalarProduct((punto2-referencia).Normalized)); // Point3D v1 = pr.Scaled(d*pr.ScalarProduct((punto1-referencia).Normalized)); // if (v1.Normalized.ScalarProduct(v2.Normalized)>0) // Estan en el mismo semiplano // { //// double distance = distancePointRect(punto2.X,punto2.Z,to.X,to.Z,from.X,from.Z); // if (v2.Norm<radius) // return v2.Normalized.Scaled(radius-v2.Norm); //// if (Math.Abs(distance)<radius) //// return pr.Normalized.Scaled(radius+distance); // else return new Point3D(0,0,0); // } // else //Estan en semiplanos distintos ==> hubo colision // { // return -v2.Normalized.Scaled(radius)-v2; // } return(new Point3D(0, 0, 0)); }