/** * Turn angle. * * @param current the current * @param target the target * @return the float */ public static float turnAngle(float current, float target) { // assuming current and target are both between 0 and TWO_PI current = PApplet.radians(current); target = PApplet.radians(target); float angle = target - current; if (angle > PConstants.PI) angle -= PConstants.TWO_PI; if (angle < -PConstants.PI) angle += PConstants.TWO_PI; return PApplet.degrees(angle); }
public InteractModel setupDisplay() { parent.noStroke(); // NoStroke para que muestre el material // parent.stroke(255,0,0); // parent.strokeWeight(1); parent.rotateX(PApplet.radians(90)); parent.rotateY(PApplet.radians(180)); return this; }
public void render() { // Draw a triangle rotated in the direction of velocity float theta = vel.heading2D() + PApplet.radians(90); fill(100); stroke(0); pushMatrix(); translate(loc.x, loc.y); rotate(theta); beginShape(PConstants.TRIANGLES); vertex(0, -r * 2); vertex(-r, r * 2); vertex(r, r * 2); endShape(); if (debug) { stroke(50); line(0, 0, 0, -sight); } popMatrix(); }
public void moveNormals() { changeMode(); pApplet.pushMatrix(); for (int j = 0; j < model.getSegmentCount(); j++) { Segment segment = model.getSegment(j); Face[] faces = segment.getFaces(); pApplet.beginShape(PConstants.QUADS); for (int i = 0; i < faces.length; i++) { PVector[] vertices = faces[i].getVertices(); PVector normal = faces[i].getNormal(); float nor = PApplet.abs(PApplet.sin(PApplet.radians((pApplet.frameCount + i))) * 100); for (PVector vertex : vertices) { pApplet.vertex( vertex.x + (normal.x * nor), vertex.y + (normal.y * nor), vertex.z + (normal.z * nor)); } } pApplet.endShape(); } pApplet.popMatrix(); }
/** * Inits the. * * @param x the x * @param y the y * @param width the width * @param height the height */ private void init(float x, float y, float width, float height) { this.setNoStroke(true); this.setFillColor(new MTColor(255, 255, 255, 150)); overlayGroup = new MTOverlayContainer(app, "Window Menu Overlay Group"); if (menuImage == null) { menuImage = app.loadImage( MT4jSettings.getInstance().getDefaultImagesPath() + "blackRoundSolidCorner64sh2.png"); } if (MT4jSettings.getInstance().isOpenGlMode()) { GLTextureSettings ts = new GLTextureSettings(); ts.wrappingHorizontal = WRAP_MODE.CLAMP; ts.wrappingVertical = WRAP_MODE.CLAMP; GLTexture glTex = new GLTexture(app, menuImage.width, menuImage.height, ts); glTex.loadGLTexture(menuImage); this.setTexture(glTex); } else { this.setTexture(menuImage); } AbstractShape menuShape = this; menuShape.unregisterAllInputProcessors(); menuShape.removeAllGestureEventListeners(DragProcessor.class); menuShape.registerInputProcessor(new DragProcessor(app)); float buttonWidth = 80; float buttonHeight = 80; final float buttonOpacity = 170; // CLOSE BUTTON // Vector3D a = new Vector3D(-width * 1.2f, height/2f); Vector3D a = new Vector3D(-width * 1.55f, 0); a.rotateZ(PApplet.radians(80)); final MTRectangle closeButton = new MTRectangle(app, x + a.x, y + a.y, buttonWidth, buttonHeight); if (closeButtonImage == null) { closeButtonImage = app.loadImage(MT4jSettings.getInstance().getDefaultImagesPath() + "closeButton64.png"); } closeButton.setTexture(closeButtonImage); closeButton.setFillColor(new MTColor(255, 255, 255, buttonOpacity)); closeButton.setNoStroke(true); closeButton.setVisible(false); closeButton.removeAllGestureEventListeners(DragProcessor.class); closeButton.removeAllGestureEventListeners(RotateProcessor.class); closeButton.removeAllGestureEventListeners(ScaleProcessor.class); this.addChild(closeButton); // Check if this menu belongs to a window Scene (MTSceneWindow) // or was added to a normal scene // -> if its not a windowed scene we dont display the Restore button if (this.windowedScene) { // RESTORE BUTTON Vector3D b = new Vector3D(-width * 1.55f, 0); b.rotateZ(PApplet.radians(10)); final MTRectangle restoreButton = new MTRectangle(app, x + b.x, y + b.y, buttonWidth, buttonHeight); if (restoreButtonImage == null) { restoreButtonImage = app.loadImage( MT4jSettings.getInstance().getDefaultImagesPath() + "restoreButton64.png"); } restoreButton.setTexture(restoreButtonImage); restoreButton.setFillColor(new MTColor(255, 255, 255, buttonOpacity)); restoreButton.setNoStroke(true); restoreButton.setVisible(false); restoreButton.removeAllGestureEventListeners(DragProcessor.class); restoreButton.removeAllGestureEventListeners(RotateProcessor.class); restoreButton.removeAllGestureEventListeners(ScaleProcessor.class); this.addChild(restoreButton); menuShape.addGestureListener( DragProcessor.class, new IGestureEventListener() { public boolean processGestureEvent(MTGestureEvent ge) { DragEvent de = (DragEvent) ge; switch (de.getId()) { case MTGestureEvent.GESTURE_STARTED: restoreButton.setVisible(true); closeButton.setVisible(true); unhighlightButton(closeButton, buttonOpacity); unhighlightButton(restoreButton, buttonOpacity); break; case MTGestureEvent.GESTURE_UPDATED: // Mouse over effect if (closeButton.containsPointGlobal(de.getTo())) { highlightButton(closeButton); } else { unhighlightButton(closeButton, buttonOpacity); } if (restoreButton.containsPointGlobal(de.getTo())) { highlightButton(restoreButton); } else { unhighlightButton(restoreButton, buttonOpacity); } break; case MTGestureEvent.GESTURE_ENDED: unhighlightButton(closeButton, buttonOpacity); unhighlightButton(restoreButton, buttonOpacity); InputCursor cursor = de.getDragCursor(); Vector3D restoreButtonIntersection = restoreButton.getIntersectionGlobal( Tools3D.getCameraPickRay( getRenderer(), restoreButton, cursor.getCurrentEvtPosX(), cursor.getCurrentEvtPosY())); if (restoreButtonIntersection != null) { logger.debug("--> RESTORE!"); MTSceneMenu.this.sceneTexture.restore(); } Vector3D closeButtonIntersection = closeButton.getIntersectionGlobal( Tools3D.getCameraPickRay( getRenderer(), closeButton, cursor.getCurrentEvtPosX(), cursor.getCurrentEvtPosY())); if (closeButtonIntersection != null) { // if (app.popScene()){ // app.removeScene(scene); //FIXME wont work if the scene has a // transition because we cant remove the still active scene //// destroy(); //this will be destroyed with the scene // sceneTexture.destroy(); //destroys also the MTSceneWindow and with it // the scene // logger.debug("--> CLOSE!"); // } if (sceneTexture.restore()) { // app.removeScene(scene); //FIXME wont work if the scene has a // transition because we cant remove the still active scene // destroy(); //this will be destroyed with the scene sceneTexture .destroy(); // destroys also the MTSceneWindow and with it the scene logger.debug("--> CLOSE!"); } } restoreButton.setVisible(false); closeButton.setVisible(false); break; default: break; } return false; } }); } else { if (scene != null) { menuShape.addGestureListener( DragProcessor.class, new IGestureEventListener() { public boolean processGestureEvent(MTGestureEvent ge) { DragEvent de = (DragEvent) ge; switch (de.getId()) { case MTGestureEvent.GESTURE_STARTED: closeButton.setVisible(true); unhighlightButton(closeButton, buttonOpacity); break; case MTGestureEvent.GESTURE_UPDATED: // Mouse over effect if (closeButton.containsPointGlobal(de.getTo())) { highlightButton(closeButton); } else { unhighlightButton(closeButton, buttonOpacity); } break; case MTGestureEvent.GESTURE_ENDED: unhighlightButton(closeButton, buttonOpacity); InputCursor cursor = de.getDragCursor(); Vector3D closeButtonIntersection = closeButton.getIntersectionGlobal( Tools3D.getCameraPickRay( getRenderer(), closeButton, cursor.getCurrentEvtPosX(), cursor.getCurrentEvtPosY())); if (closeButtonIntersection != null) { if (app.popScene()) { destroy(); // Destroy this scene.destroy(); // Destroy the scene logger.debug("--> CLOSE!"); } } closeButton.setVisible(false); break; default: break; } return false; } }); } } }