Example #1
0
/**
 * Fire a railgun slug.
 * @param p q2jgame.Player
 * @param start q2java.Vec3
 * @param forward q2java.Vec3
 * @param damage int
 * @param kick int
 */
public static void fireRail(GameObject p, Point3f start, Vector3f aimDir, int damage, int kick) 
	{
	TraceResults	tr = null;
	NativeEntity 	ignore;
	int			mask;
	boolean		water;
	Point3f		from = new Point3f(start);
	Point3f		end = new Point3f();

	end.scaleAdd(8192, aimDir, start);
	ignore = p.fEntity;
	water = false;
	mask = Engine.MASK_SHOT | Engine.CONTENTS_SLIME | Engine.CONTENTS_LAVA;
	while (ignore != null)
		{
		tr = Engine.trace(from, end, ignore, mask);

		if ((tr.fContents & (Engine.CONTENTS_SLIME | Engine.CONTENTS_LAVA)) != 0)
			{
			mask &= ~(Engine.CONTENTS_SLIME | Engine.CONTENTS_LAVA);
			water = true;
			}
		else
			{
/*			if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
				ignore = tr.ent;
			else
*/				ignore = null;

			if ((tr.fEntity.getReference() != p) && (tr.fEntity.getReference() instanceof GameObject))
				((GameObject)tr.fEntity.getReference()).damage(p, p, aimDir, tr.fEndPos, tr.fPlaneNormal, damage, kick, 0, Engine.TE_NONE, "railgun"); 
			}

		from.set(tr.fEndPos);
		}

	// send gun puff / flash
	Engine.writeByte(Engine.SVC_TEMP_ENTITY);
	Engine.writeByte(Engine.TE_RAILTRAIL);
	Engine.writePosition(start);
	Engine.writePosition(tr.fEndPos);
	Engine.multicast(p.fEntity.getOrigin(), Engine.MULTICAST_PHS);
	if (water)
		{
	   	Engine.writeByte(Engine.SVC_TEMP_ENTITY);
		Engine.writeByte(Engine.TE_RAILTRAIL);
		Engine.writePosition(start);
		Engine.writePosition(tr.fEndPos);
		Engine.multicast(tr.fEndPos, Engine.MULTICAST_PHS);
		}
	}
  public static void zoomToFit(Viewport2 viewport) {
    ViewDefinition viewdef = viewport.getViewDefinition();
    // if (MainFrame.getInstance().getMeshToolBar().getMode() != MeshToolBar.VIEW_ZOOM) {
    //	MainFrame.getInstance().getJPatchScreen().removeAllMouseListeners();
    //	MainFrame.getInstance().getJPatchScreen().addMouseListeners(new
    // ChangeViewMouseListener(MouseEvent.BUTTON1,ChangeViewMouseListener.ZOOM));
    //	MainFrame.getInstance().getMeshToolBar().setMode(MeshToolBar.VIEW_ZOOM);
    // } else {
    //	MainFrame.getInstance().getMeshToolBar().reset();
    // }
    Selection selection = MainFrame.getInstance().getSelection();
    float left = Float.MAX_VALUE;
    float right = -Float.MAX_VALUE;
    float bottom = Float.MAX_VALUE;
    float top = -Float.MAX_VALUE;
    Point3f p3 = new Point3f();
    Matrix4f m4View = viewdef.getScreenMatrix();
    // Matrix3f m3RotScale = new Matrix3f();
    // m4View.getRotationScale(m3RotScale);
    boolean doit = true;
    if (selection != null && !selection.isSingle()) {
      for (Iterator it = selection.getObjects().iterator(); it.hasNext(); ) {
        Object object = it.next();
        if (object instanceof ControlPoint) {
          p3.set(((ControlPoint) object).getPosition());
          m4View.transform(p3);
          if (p3.x < left) left = p3.x;
          if (p3.x > right) right = p3.x;
          if (p3.y < bottom) bottom = p3.y;
          if (p3.y > top) top = p3.y;
        }
      }
    } else {
      ArrayList heads = MainFrame.getInstance().getModel().allHeads();
      int p = 0;
      for (Iterator it = heads.iterator(); it.hasNext(); ) {
        ControlPoint cp = (ControlPoint) it.next();
        if (!cp.isHidden()) {
          p3.set(cp.getPosition());
          m4View.transform(p3);
          if (p3.x < left) left = p3.x;
          if (p3.x > right) right = p3.x;
          if (p3.y < bottom) bottom = p3.y;
          if (p3.y > top) top = p3.y;
          p++;
        }
      }
      doit = (p >= 2);
    }
    if (doit) {
      // System.out.println(left + " " + right + " " + top + " " + bottom + " " +
      // viewdef.getScale());
      // System.out.println(viewdef.getTranslateX() + " " + viewdef.getTranslateY());
      float centerX = (left + right) / 2f;
      float centerY = (top + bottom) / 2f;
      float dimX = viewdef.getWidth() / 2f;
      float dimY = viewdef.getHeight() / 2f;
      float sizeX = right - centerX;
      float sizeY = top - centerY;
      if (sizeX > 0 || sizeY > 0) {
        // System.out.println(centerX + ":" + centerY);

        float scaleX = dimX / sizeX;
        float scaleY = dimY / sizeY;
        float scale = Math.min(scaleX, scaleY) * 0.9f;
        // viewdef.setScale(viewdef.getScale() * scale);
        viewdef.setLock(null);
        viewdef.moveView(-centerX / dimX + 1, (dimY - centerY) / dimX, false);
        viewdef.scaleView(scale);
        // viewdef.setTranslation(centerX, centerY);
        // viewdef.computeMatrix();
        // viewport.render();
      }
    }
  }
  /**
   * Computes the new transform for this interpolator for a given alpha value.
   *
   * @param alphaValue alpha value between 0.0 and 1.0
   * @param transform object that receives the computed transform for the specified alpha value
   * @since Java 3D 1.3
   */
  public void computeTransform(float alphaValue, Transform3D transform) {
    // compute the current value of u from alpha and the
    // determine lower and upper knot points
    computePathInterpolation(alphaValue);

    // Determine the segment within which we will be interpolating
    currentSegmentIndex = this.lowerKnot - 1;

    // if we are at the start of the curve
    if (currentSegmentIndex == 0 && currentU == 0f) {
      iHeading = keyFrames[1].heading;
      iPitch = keyFrames[1].pitch;
      iBank = keyFrames[1].bank;
      iPos.set(keyFrames[1].position);
      iScale.set(keyFrames[1].scale);

      // if we are at the end of the curve
    } else if (currentSegmentIndex == (numSegments - 1) && currentU == 1.0) {
      iHeading = keyFrames[upperKnot].heading;
      iPitch = keyFrames[upperKnot].pitch;
      iBank = keyFrames[upperKnot].bank;
      iPos.set(keyFrames[upperKnot].position);
      iScale.set(keyFrames[upperKnot].scale);

      // if we are somewhere in between the curve
    } else {
      // Get a reference to the current spline segment i.e. the
      // one bounded by lowerKnot and upperKnot
      currentSegment = cubicSplineCurve.getSegment(currentSegmentIndex);

      // interpolate quaternions
      iHeading = currentSegment.getInterpolatedHeading(currentU);
      iPitch = currentSegment.getInterpolatedPitch(currentU);
      iBank = currentSegment.getInterpolatedBank(currentU);

      // interpolate position
      currentSegment.getInterpolatedPositionVector(currentU, iPos);

      // interpolate position
      currentSegment.getInterpolatedScale(currentU, iScale);
      // System.out.println("Pos :" + iPos);
    }

    // Modification by ReubenDB

    if (colorRampingInterpolate == true) {
      float[] curPos = new float[3];
      iPos.get(curPos);

      myColorRamp.getColor(curPos[1], histColor);
      // System.out.println("SETING COLOR:" + histColor + " CurPos: " + curPos[0] + ", " + curPos[1]
      // + ", " + curPos[2]);
      objectCA.setColor(histColor);
      // System.out.println("CurrentAlpha = " + myAlpha.value());
    }

    if (timeDisplayInterpolate == true) {
      myTimeDisplay.updateDisplayFromAlpha(myAlpha.value());
      // System.out.println(myAlpha.value());
    }

    // Generate a transformation matrix in tMat using interpolated
    // heading, pitch and bank
    pitchMat.setIdentity();
    pitchMat.rotX(-iPitch);
    bankMat.setIdentity();
    bankMat.rotZ(iBank);
    tMat.setIdentity();
    tMat.rotY(-iHeading);
    tMat.mul(pitchMat);
    tMat.mul(bankMat);

    // TODO: Vijay - Handle Non-Uniform scale
    // Currently this interpolator does not handle non uniform scale
    // We cheat by just taking the x scale component

    // Scale the transformation matrix
    sMat.set((double) iScale.x);
    tMat.mul(sMat);

    // Set the translation components.
    tMat.m03 = iPos.x;
    tMat.m13 = iPos.y;
    tMat.m23 = iPos.z;
    rotation.set(tMat);

    // construct a Transform3D from:  axis * rotation * axisInverse
    transform.mul(axis, rotation);
    transform.mul(transform, axisInverse);
  }