public RadiosityIntersection Intersection(Microsoft.DirectX.Vector3 origin, Microsoft.DirectX.Vector3 direction) { Vector3 newDir = AngleTransform(transform.Pitch, transform.Yaw, transform.Roll, direction); direction = new Vector3(-direction.X, direction.Y, direction.Z); Vector3 closeVector = new Vector3(origin.X - transform.X, origin.Y - transform.Y, origin.Z - transform.Z); origin = new Vector3(-origin.X, origin.Y, origin.Z); Vector4 vector4 = Vector3.Transform(direction, transform.matrix); direction = new Vector3(vector4.X - transform.X, vector4.Y - transform.Y, vector4.Z - transform.Z); //direction.Normalize(); //direction = newDir; vector4 = Vector3.Transform(origin, transform.matrix); origin = new Vector3(vector4.X, vector4.Y, vector4.Z); RadiosityIntersection m = @base.Intersection(direction, origin); //if (!m.NoIntersection) // System.Diagnostics.Debugger.Break(); vector4 = Vector3.Transform(m.Position, Inverse); m.Position = new Vector3(-vector4.X, vector4.Y, vector4.Z); vector4 = Vector3.Transform(m.NewDirection, Inverse); m.NewDirection = new Vector3(-vector4.X, vector4.Y, vector4.Z); return(m); }
public Interfaces.Rendering.Radiosity.RadiosityIntersection Intersection(Vector3 direction, Vector3 origin) { //TODO: First check for bounding box collision. Interfaces.Rendering.Radiosity.RadiosityIntersection intersect = RadiosityIntersect(origin, direction); intersect.Scale = 1.0f; intersect.LightmapIndex = -1; return(intersect); }
private Interfaces.Rendering.Radiosity.RadiosityIntersection RadiosityIntersect(Vector3 origin, Vector3 direction) { if (direction.Length() != 1) { direction.Normalize(); } // TODO: Check bounding box for model, then for each node, then for each bsp. Interfaces.Rendering.Radiosity.RadiosityIntersection closest = RadiosityIntersection.None; // if (ax + by + cz == -D) then COLLISION foreach (NodeBlock node in modelCollisionGeometryValues._nodesList) { foreach (BspBlock bsp in node.Bsps) { //cosAlpha = DotProduct( // vnRayVector , vnPlaneNormal ); // if (cosAlpha==0) return -1.0f; // deltaD = planeD - // DotProduct(vRayOrigin,vnPlaneNormal); // return (deltaD/cosAlpha); int surfaceIndex = 0; foreach (SurfaceBlock surface in bsp.Surfaces) { RadiosityIntersection tempIntersect = Ray.IntersectRayOnPlane(new Ray(origin, direction), new Plane(bsp.Planes[surface.Plane.Value].Plane.I, bsp.Planes[surface.Plane.Value].Plane.J, bsp.Planes[surface.Plane.Value].Plane.K, bsp.Planes[surface.Plane.Value].Plane.D)); if ((bool)tempIntersect) { if (closest != RadiosityIntersection.None) { if (closest.Distance < tempIntersect.Distance) { continue; } } closest = tempIntersect; } } } } return(closest); }
/// <summary> /// Computes 1) a boolean specifying whether the intersection was on the right side 2) the lightmap UVs 3) the texture sample color 4) the new ray direction. /// </summary> /// <param name="direction">The direction the photon was traveling when it struck the surface.</param> /// <param name="a">Triangle vertex.</param> /// <param name="b">Triangle vertex.</param> /// <param name="c">Triangle vertex.</param> /// <param name="intersection">Intersection data returned by EnhancedMesh.Intersect</param> /// <param name="textureSampler">A sampler to sample the BSPs basemap texture.</param> /// <returns></returns> public static RadiosityIntersection ProcessIntersection(Vector3 direction, Vertex a, Vertex b, Vertex c, Intersection intersection, Sampler textureSampler, bool specular) { if (intersection == Intersection.None) { return(RadiosityIntersection.None); } RadiosityIntersection radIntersect = new RadiosityIntersection(intersection); Vector3 normal = ComputeTriangleNormal(a, b, c); radIntersect.WrongSide = CheckCollisionSide(direction, normal); if (Random.NextDouble() > RadiosityDiffuseConstant) { radIntersect.Absorbed = true; } if (specular) { radIntersect.NewDirection = SpecularReflect(direction, normal); } else { radIntersect.NewDirection = DiffuseReflect(normal); } radIntersect.Scale = 1f; // TODO: Is this even necessary? Vector2 lightmapUV = ConvertBaryToTextureCoords(a, b, c, intersection); Vector2 textureUV = ConvertBaryToTextureCoords(a, b, c, intersection); radIntersect.U = lightmapUV.X; radIntersect.V = lightmapUV.Y; if (textureSampler != null) { radIntersect.TextureSampleColor = textureSampler.Sample(textureUV); } return(radIntersect); }
public void ProcessCollision(RadiosityIntersection intersection) { throw new Exception("The method or operation is not implemented."); }