public int[] rayTrace(Ray ray, int depth) { double t = Double.MAX_VALUE; RenderObject res = null; for (int i = 0; i < s.o.objectsArray.size(); i++) { RenderObject curr = s.o.objectsArray.get(i); double triceratops = getT(ray, curr); if (triceratops != -1 && triceratops < t) { t = triceratops; res = curr; } } if (res == null) { System.out.println("test"); return s.ac; } Coord Trex = ray.p0C.add(ray.p0C, ray.uC.multiply(ray.uC, t)); Coord norm = res.getNormalAt(Trex); // int[] color = new int[3]; // int materID = s.o.get_obj_by_id(res.id).matId; // Material w = s.m.materialArray.get(materID); // for (int j = 0; j < 3; j++){ // color[j] = (int)(w.rgb[j] * 255); // } return rayShade(res, ray, Trex, norm, depth); // // // // return color; }
public void stopVisualizing() { synchronized (startStopSynchObject) { if (!currentlyRunning || currentlyStopping) { return; } currentlyStopping = true; if (currentlyStarting) { System.err.println( "Got through all of the stopping conditions, we're going to stop... but its currently starting....ahhh"); } } // tell them all to die for (RenderObject thisRunner : theRenderObjects) { thisRunner.kill(); } // wait for them all to be done for (Thread thisThread : theThreads) { try { thisThread.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } theThreads.removeAllElements(); synchronized (startStopSynchObject) { currentlyStopping = false; currentlyRunning = false; } }
public double getT(Ray r, RenderObject o) { Matrix m = new Matrix(); double[][] u = r.u3; double[][] ut = m.tMatrix(u); double[][] p = r.p0C.subtract(r.p0C, o.getOrigin()).toArray3D(); double[][] pt = m.tMatrix(p); double[][] aa = m.multiplyMatrix(ut, u); double a = aa[0][0]; double bb[][] = m.multiplyMatrix(ut, p); double b = bb[0][0] * 2; double cc[][] = m.multiplyMatrix(pt, p); double cee = cc[0][0] - (o.getRadius() * o.getRadius()); double existance = (b * b) - (4 * a * cee); if (existance < 0) { return -1; } else { double t1 = ((-1 * b) + Math.sqrt(existance)) / (2 * a); double t2 = ((-1 * b) - Math.sqrt(existance)) / (2 * a); if (t1 < 0 && t2 < 0) { return -1; } else if (t1 < 0) { return t2; } else if (t2 < 0) { return t1; } else { return Math.min(t1, t2); } } }
public synchronized void redrawCurrentImage() { if (verbose) { System.out.println("redrawCurrentImage called"); System.out.flush(); } synchronized (redrawLock) { scheduled = false; drawing = true; } if (verbose) { System.out.println("redraw lock taken"); System.out.flush(); } Graphics2D G = bufferEnvImage.createGraphics(); Color myClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); G.setColor(myClearColor); G.setBackground(myClearColor); G.clearRect(0, 0, bufferEnvImage.getWidth(), bufferEnvImage.getHeight()); /* * Cycle through SelfUpdatingVizComponents (e.g., CarOnMountainComponent for mountain car) and * call getProductionImage(), which calls render()(?). */ for (int i = 0; i < theRenderObjects.size(); i++) { RenderObject thisRunner = theRenderObjects.get(i); Dimension position = makeLocationForVizComponent(i); G.drawImage(thisRunner.getProductionImage(), position.width, position.height, null); } // Make generated image official as productionEnvImage BufferedImage tmpImage = productionEnvImage; productionEnvImage = bufferEnvImage; bufferEnvImage = tmpImage; synchronized (redrawLock) { lastDrawTime = System.currentTimeMillis(); drawing = false; } if (verbose) { System.out.println("redraw finished. parentPanel: " + parentPanel.getClass().getSimpleName()); System.out.flush(); } parentPanel.receiveNotificationVizChanged(); super.notifyObservers(productionEnvImage); }
/** * Build a tree of RenderObjects that mirrors the tree of SceneObjects in <scene>. * * <p>After the objects are created and linked up using the RenderObject.parent and * RenderObject.children fields, the frame-to-world transformations of all objects are computed. * * @param scene * @param env */ public static void buildTree(Scene scene, RenderEnvironment env) { // Clear Out Any Old Data env.cameras.clear(); env.lights.clear(); // Pass 1: Create The Render Object Mapping HashMap<String, RenderObject> dict = new HashMap<>(); for (SceneObject so : scene.objects) { RenderObject ro; if (so instanceof SceneCamera) { ro = new RenderCamera(so, env.viewportSize); env.cameras.add((RenderCamera) ro); } else if (so instanceof SceneLight) { ro = new RenderLight(so); env.lights.add((RenderLight) ro); } else { ro = new RenderObject(so); } dict.put(so.getID().name, ro); } // Pass 2: Create Parent-Children Bindings for (SceneObject so : scene.objects) { if (so.parent != null) { // Get The Child RenderObject o = dict.get(so.getID().name); if (o != null) { // Get The Parent RenderObject p = dict.get(so.parent); if (p != null) { // Bind Child And Parent p.children.add(o); o.parent = p; } } } } // Pass 3: Find A Root Node If It Exists env.root = dict.get("World"); rippleTransformations(env); // Set Up Render State env.linkObjectResources(); }
@Override protected void update() { super.update(); drift(); long currentTime = System.currentTimeMillis(); float elapsedTime = (currentTime - startTime) / 1000.0f; if (elapsedTime >= c_bulletLifetime) { destroy(); } }
@Override protected void doRender(GL10 gl) { setColor(gl, this.color); super.doRender(gl); }
@Override protected void render(IRenderObject renderObject, float boxTranslation) { if (renderObject != null && renderObject.getObject() instanceof EntityAethon) { RenderObject o = (RenderObject) renderObject; EntityAethon aethon = (EntityAethon) o.getEntity(); boolean isFlying = aethon.isFlying(); float swingProgress = o.swingProgress; float swingProgressPrev = o.swingProgressPrev; float wingDistMulti = 5F; float wingSpeed = isFlying ? 1.75F : 20F; float neckSpeed = isFlying ? 8F : 18F; float tailSpeed = isFlying ? 4F : 18F; long ticks = aethon.ticksExisted; if (isFlying) { this.rThigh.rotateAngleX = (float) Math.toRadians(-44F); this.lThigh.rotateAngleX = (float) Math.toRadians(-44F); this.rArm.rotateAngleX = (float) Math.toRadians(-18F); this.lArm.rotateAngleX = (float) Math.toRadians(-18F); this.neck1.rotateAngleX = (float) Math.toRadians((Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.neck2.rotateAngleX = (float) Math.toRadians((Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.neck3.rotateAngleX = (float) Math.toRadians((Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.neck4.rotateAngleX = (float) Math.toRadians((Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.tail1.rotateAngleX = (float) Math.toRadians(-82F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail2.rotateAngleX = (float) Math.toRadians(-12F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail3.rotateAngleX = (float) Math.toRadians(0F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail4.rotateAngleX = (float) Math.toRadians(0F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail5.rotateAngleX = (float) Math.toRadians(0F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.lWingArm.rotateAngleY = (float) Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 3F) * wingDistMulti)); this.lWingArm.rotateAngleZ = (float) Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 2F) * wingDistMulti)); this.lWingArm.rotateAngleZ = (float) Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 10F) * wingDistMulti)); this.lWingArm2.rotateAngleX = (float) Math.toRadians( (100F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 6F) * wingDistMulti)); this.lWingArm2.rotateAngleY = (float) -Math.toRadians( (30F + (Math.cos((ticks + Game.partialTicks()) / (wingSpeed)) * 4F) * wingDistMulti)); this.lWingArm2.rotateAngleZ = (float) Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 4F) * wingDistMulti)); this.rWingArm.rotateAngleY = (float) -Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 3F) * wingDistMulti)); this.rWingArm.rotateAngleZ = (float) -Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 2F) * wingDistMulti)); this.rWingArm.rotateAngleZ = (float) -Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 10F) * wingDistMulti)); this.rWingArm2.rotateAngleX = (float) Math.toRadians( (100F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 6F) * wingDistMulti)); this.rWingArm2.rotateAngleY = (float) Math.toRadians( (30F + (Math.cos((ticks + Game.partialTicks()) / (wingSpeed)) * 4F) * wingDistMulti)); this.rWingArm2.rotateAngleZ = (float) -Math.toRadians( (40F + (Math.sin((ticks + Game.partialTicks()) / (wingSpeed)) * 4F) * wingDistMulti)); } else { this.rThigh.rotateAngleX = (float) (Math.toRadians(-44F) + MathHelper.cos(swingProgress * 0.3662F) * 0.9F * swingProgressPrev); this.lThigh.rotateAngleX = (float) (Math.toRadians(-44F) + MathHelper.sin(swingProgress * 0.3662F) * 0.9F * swingProgressPrev); this.rArm.rotateAngleX = (float) (Math.toRadians(-18F) + MathHelper.cos(swingProgress * 0.3662F) * 0.6F * swingProgressPrev + 0.6665191F); this.lArm.rotateAngleX = (float) (Math.toRadians(-18F) + MathHelper.sin(swingProgress * 0.3662F) * 0.6F * swingProgressPrev + 0.6665191F); this.neck1.rotateAngleX = (float) Math.toRadians((Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.neck2.rotateAngleX = (float) Math.toRadians(16F + (Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.neck3.rotateAngleX = (float) Math.toRadians(16F + (Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.neck4.rotateAngleX = (float) Math.toRadians(19F + (Math.sin((ticks + Game.partialTicks()) / (neckSpeed)) * 3F)); this.tail1.rotateAngleX = (float) Math.toRadians(-72F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail2.rotateAngleX = (float) Math.toRadians(16F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail3.rotateAngleX = (float) Math.toRadians(16F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail4.rotateAngleX = (float) Math.toRadians(19F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.tail5.rotateAngleX = (float) Math.toRadians(19F + (Math.sin((ticks + Game.partialTicks()) / (tailSpeed)) * 3F)); this.lWingArm.rotateAngleX = (float) Math.toRadians(-41.74F); this.lWingArm.rotateAngleY = (float) Math.toRadians(0F); this.lWingArm.rotateAngleZ = (float) Math.toRadians(23.48F); this.lWingArm2.rotateAngleX = (float) Math.toRadians(23.48F); this.lWingArm2.rotateAngleY = (float) Math.toRadians(10.29F); this.lWingArm2.rotateAngleZ = (float) Math.toRadians(-12.86F); this.rWingArm.rotateAngleX = (float) Math.toRadians(-41.74F); this.rWingArm.rotateAngleY = (float) Math.toRadians(0F); this.rWingArm.rotateAngleZ = (float) Math.toRadians(-23.48F); this.rWingArm2.rotateAngleX = (float) Math.toRadians(23.48F); this.rWingArm2.rotateAngleY = (float) Math.toRadians(-10.29F); this.rWingArm2.rotateAngleZ = (float) Math.toRadians(12.86F); } OpenGL.pushMatrix(); { if (isFlying) { OpenGL.rotate(75F, 1, 0, 0); } this.rWingArm.render(boxTranslation); this.rArm.render(boxTranslation); this.lWingArm.render(boxTranslation); this.lArm.render(boxTranslation); this.chest.render(boxTranslation); } OpenGL.popMatrix(); } else { this.rWingArm.render(boxTranslation); this.rArm.render(boxTranslation); this.lWingArm.render(boxTranslation); this.lArm.render(boxTranslation); this.chest.render(boxTranslation); } }