public double[] calculateIntensity(Point p, Vector normal, Point e) { l = new Vector(position, p); n = normal; v = new Vector(e, p); normalizeVectors(); calculateReflectionVector(); for (int color = 0; color < 3; color++) { I[color] = attenuation * (Kd * L[color][DIFFUSE] * Math.max(Vector.dotProduct(l, n), 0) + Ks * L[color][SPECULAR] * Math.max(Math.pow(Vector.dotProduct(r, v), 2), 0)) + Ka * L[color][AMBIENT]; } return I; }
public static Point intersectionPoint(Ray ray, Plane plane) { Vector rayToPlaneVector = vectorBetween(ray.point, plane.point); float scaleFactor = rayToPlaneVector.dotProduct(plane.normal) / ray.vector.dotProduct(plane.normal); Point intersectionPoint = ray.point.translate(ray.vector.scale(scaleFactor)); return intersectionPoint; }
private void calculateReflectionVector() { r = Vector.add( l, Vector.multiplyVector( n, (2 * Vector.dotProduct(l, n) / (Math.pow(n.getMagnitude(), 2)))) .neg()); r.normalize(); }
public void display(GLAutoDrawable drawable) { update(); GL2 gl = drawable.getGL().getGL2(); // Clear Color Buffer, Depth Buffer gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); Matrix TmpMatrix = new Matrix(); // Temporary MATRIX Structure ( NEW ) Vector TmpVector = new Vector(), TmpNormal = new Vector(); // Temporary // VECTOR // Structures // ( NEW ) gl.glLoadIdentity(); // Reset The Matrix if (outlineSmooth) { // Check To See If We Want Anti-Aliased Lines ( NEW // ) gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); // Use The Good // Calculations // ( NEW ) gl.glEnable(GL2.GL_LINE_SMOOTH); // Enable Anti-Aliasing ( NEW ) } else // We Don't Want Smooth Lines ( NEW ) gl.glDisable(GL2.GL_LINE_SMOOTH); // Disable Anti-Aliasing ( NEW ) gl.glTranslatef(0.0f, 0.0f, -2.0f); // Move 2 Units Away From The Screen // ( NEW ) gl.glRotatef(modelAngle, 0.0f, 1.0f, 0.0f); // Rotate The Model On It's // Y-Axis ( NEW ) gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, TmpMatrix.Data, 0); // Get // The // Generated // Matrix // ( // NEW // ) // Cel-Shading Code // gl.glEnable(GL2.GL_TEXTURE_1D); // Enable 1D Texturing ( NEW ) gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind Our // Texture ( NEW // ) gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW ) gl.glBegin(GL2.GL_TRIANGLES); // Tell OpenGL That We're Drawing // Triangles // Loop Through Each Polygon for (int i = 0; i < polyNum; i++) // Loop Through Each Vertex for (int j = 0; j < 3; j++) { // Fill Up The TmpNormal Structure With TmpNormal.X = polyData[i].Verts[j].Nor.X; // The Current Vertices' Normal Values TmpNormal.Y = polyData[i].Verts[j].Nor.Y; TmpNormal.Z = polyData[i].Verts[j].Nor.Z; // Rotate This By The Matrix TmpMatrix.rotateVector(TmpNormal, TmpVector); // Normalize The New Normal TmpVector.normalize(); // Calculate The Shade Value float TmpShade = Vector.dotProduct(TmpVector, lightAngle); // Clamp The Value to 0 If Negative ( NEW ) if (TmpShade < 0.0f) { TmpShade = 0.0f; } // Set The Texture Co-ordinate As The Shade Value gl.glTexCoord1f(TmpShade); // Send The Vertex Position gl.glVertex3f( polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z); } gl.glEnd(); // Tell OpenGL To Finish Drawing gl.glDisable(GL2.GL_TEXTURE_1D); // Disable 1D Textures ( NEW ) // Outline Code // Check To See If We Want To Draw The Outline if (outlineDraw) { // Enable Blending gl.glEnable(GL2.GL_BLEND); // Set The Blend Mode gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); // Draw Backfacing Polygons As Wireframes gl.glPolygonMode(GL2.GL_BACK, GL2.GL_LINE); // Set The Line Width gl.glLineWidth(outlineWidth); // Don't Draw Any Front-Facing Polygons gl.glCullFace(GL2.GL_FRONT); // Change The Depth Mode gl.glDepthFunc(GL2.GL_LEQUAL); // Set The Outline Color gl.glColor3fv(outlineColor, 0); // Tell OpenGL What We Want To Draw gl.glBegin(GL2.GL_TRIANGLES); // Loop Through Each Polygon for (int i = 0; i < polyNum; i++) { // Loop Through Each Vertex for (int j = 0; j < 3; j++) { // Send The Vertex Position gl.glVertex3f( polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z); } } gl.glEnd(); // Tell OpenGL We've Finished // Reset The Depth-Testing Mode gl.glDepthFunc(GL2.GL_LESS); // Reset The Face To Be Culled gl.glCullFace(GL2.GL_BACK); // Reset Back-Facing Polygon Drawing Mode gl.glPolygonMode(GL2.GL_BACK, GL2.GL_FILL); // Disable Blending gl.glDisable(GL2.GL_BLEND); } // Check To See If Rotation Is Enabled if (modelRotate) { // Update Angle Based On The Clock modelAngle += .2f; } }
@Test(expected = ArithmeticException.class) public void dotTest_IllegalVectoy() { infiniteVector1.dotProduct(nilVector); }
@Test public void dotTest_PerfectParameters() { double vectorProduct = testVector1.dotProduct(testVector2); assertTrue(Util.fuzzyEquals(vectorProduct, 0)); }
public double dotProduct(int sequencePosition, Vector weights) { return weights.dotProduct(sequence[sequencePosition]); }
@Override public double dotProduct(Vector v) { if (v instanceof SparseFloatVector) return v.dotProduct(this); // actually do sparse product on other side else return super.dotProduct(v); }