Example #1
0
  private Segment addRelativeAxon(Segment parent, Point3f relPosition, float radius) {
    Point3f newPosition = (new Point3f(parent.getEndPointPosition()));
    newPosition.add(relPosition);

    String newName = "Axon_" + getOnlyAxonalSegments().size();

    Segment tempAxon = addAxonalSegment(radius, newName, newPosition, parent, 1, newName + "_Sec");
    return tempAxon;
  }
Example #2
0
  private Segment addRelativeDendrite(Segment parent, Point3f relPosition) {
    Point3f newPosition = (new Point3f(parent.getEndPointPosition()));
    newPosition.add(relPosition);

    float newRadius = parent.getRadius() * .6f;

    String newName = "Dend_" + getOnlyDendriticSegments().size();

    Segment tempDend =
        addDendriticSegment(newRadius, newName, newPosition, parent, 1, newName + "_Sec", true);
    return tempDend;
  }
Example #3
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);
		}
	}
Example #4
0
  public static SphericalRegion getEnclosingSphere(RectangularBox box) {
    Point3f centre =
        new Point3f(
            (box.getHighestXValue() + box.getLowestXValue()) / 2,
            (box.getHighestYValue() + box.getLowestYValue()) / 2,
            (box.getHighestZValue() + box.getLowestZValue()) / 2);

    float radius =
        centre.distance(
            new Point3f(box.getLowestXValue(), box.getLowestYValue(), box.getLowestZValue()));

    SphericalRegion newSphere = new SphericalRegion(centre.x, centre.y, centre.z, radius);

    return newSphere;
  }
Example #5
0
  /**
   * Compute the vertex positions for the four voxels in the current slice to be bilinearly
   * interpolated.
   *
   * @param i0 the current permuted indices of the upper left voxel in the 2x2 block of voxels in
   *     the slice
   * @param i1 DOCUMENT ME!
   * @param i2 DOCUMENT ME!
   */
  protected final void computePositions(int i0, int i1, int i2) {

    switch (m_iPermute) {
      case 0:
        m_kP00.x = i0 - (0.5f * m_aiBound[0]);
        m_kP00.y = i1 - (0.5f * m_aiBound[1]);
        m_kP00.z = i2 - (0.5f * m_aiBound[2]);
        m_kP10.x = m_kP00.x + 1.0f;
        m_kP10.y = m_kP00.y;
        m_kP10.z = m_kP00.z;
        m_kP01.x = m_kP00.x;
        m_kP01.y = m_kP00.y + 1.0f;
        m_kP01.z = m_kP00.z;
        m_kP11.x = m_kP10.x;
        m_kP11.y = m_kP01.y;
        m_kP11.z = m_kP00.z;
        break;

      case 1:
        m_kP00.y = i0 - (0.5f * m_aiBound[1]);
        m_kP00.z = i1 - (0.5f * m_aiBound[2]);
        m_kP00.x = i2 - (0.5f * m_aiBound[0]);
        m_kP10.y = m_kP00.y + 1.0f;
        m_kP10.z = m_kP00.z;
        m_kP10.x = m_kP00.x;
        m_kP01.y = m_kP00.y;
        m_kP01.z = m_kP00.z + 1.0f;
        m_kP01.x = m_kP00.x;
        m_kP11.y = m_kP10.y;
        m_kP11.z = m_kP01.z;
        m_kP11.x = m_kP00.x;
        break;

      case 2:
        m_kP00.z = i0 - (0.5f * m_aiBound[2]);
        m_kP00.x = i1 - (0.5f * m_aiBound[0]);
        m_kP00.y = i2 - (0.5f * m_aiBound[1]);
        m_kP10.z = m_kP00.z + 1.0f;
        m_kP10.x = m_kP00.x;
        m_kP10.y = m_kP00.y;
        m_kP01.z = m_kP00.z;
        m_kP01.x = m_kP00.x + 1.0f;
        m_kP01.y = m_kP00.y;
        m_kP11.z = m_kP10.z;
        m_kP11.x = m_kP01.x;
        m_kP11.y = m_kP00.y;
        break;
    }
  }
Example #6
0
/**
 * Fire a lead projectile.
 * @param p q2jgame.Player
 * @param start q2java.Vec3
 * @param aimDir q2java.Vec3
 * @param damage int
 * @param kick int
 * @param teImpact int
 * @param hSpread int
 * @param vSpread int
 */
public static void fireLead(GameObject p, Point3f start, Vector3f aimDir, int damage, int kick, int teImpact, int hSpread, int vSpread, String obitKey) 
	{
	TraceResults	tr;
	Vector3f	forward = new Vector3f();
	Vector3f	right = new Vector3f();
	Vector3f	up = new Vector3f();
	Point3f	end = new Point3f();
	float	r;
	float	u;
	Point3f		waterStart = null;
	boolean	water = false;
	int		content_mask = Engine.MASK_SHOT | Engine.MASK_WATER;

	tr = Engine.trace(p.fEntity.getOrigin(), start, p.fEntity, Engine.MASK_SHOT);
	if (!(tr.fFraction < 1.0))
		{
		// limit the scope of "dir"
			{
			Angle3f  dir = Q2Recycler.getAngle3f();
			dir.set(aimDir);
			dir.getVectors(forward, right, up);
			Q2Recycler.put(dir);
			}

		r = (float) (GameUtil.cRandom() * hSpread);
		u = (float) (GameUtil.cRandom() * vSpread);
		end.scaleAdd(8192, forward, start);
		end.scaleAdd(r, right, end);
		end.scaleAdd(u, up, end);

		if ((Engine.getPointContents(start) & Engine.MASK_WATER) != 0)
			{
			water = true;
			waterStart = new Point3f(start);
			content_mask &= ~Engine.MASK_WATER;
			}

		tr = Engine.trace(start, end, p.fEntity, content_mask);

		// see if we hit water
		if ((tr.fContents & Engine.MASK_WATER) != 0)
			{
			int		color;

			water = true;
			waterStart = new Point3f(tr.fEndPos);

			if (!start.equals(tr.fEndPos))
				{
				if ((tr.fContents & Engine.CONTENTS_WATER) != 0)
					{
					if (tr.fSurfaceName.equals("*brwater"))
						color = Engine.SPLASH_BROWN_WATER;
					else
						color = Engine.SPLASH_BLUE_WATER;
					}
				else if ((tr.fContents & Engine.CONTENTS_SLIME) != 0)
					color = Engine.SPLASH_SLIME;
				else if ((tr.fContents & Engine.CONTENTS_LAVA) != 0)
					color = Engine.SPLASH_LAVA;
				else
					color = Engine.SPLASH_UNKNOWN;

				if (color != Engine.SPLASH_UNKNOWN)
					{
					Engine.writeByte(Engine.SVC_TEMP_ENTITY);
					Engine.writeByte(Engine.TE_SPLASH);
					Engine.writeByte(8);
					Engine.writePosition(tr.fEndPos);
					Engine.writeDir(tr.fPlaneNormal);
					Engine.writeByte(color);
					Engine.multicast(tr.fEndPos, Engine.MULTICAST_PVS);
					}

				// change bullet's course when it enters water
				Vector3f diff = Q2Recycler.getVector3f();
				Angle3f ang = Q2Recycler.getAngle3f();
				
				diff.sub(end, start);
				ang.set(diff);
				ang.getVectors(forward, right, up);
				
				r = (float)(GameUtil.cRandom() * hSpread * 2);
				u = (float)(GameUtil.cRandom() * vSpread * 2);
				end.scaleAdd(8192, forward, waterStart);
				end.scaleAdd(r, right, end);
				end.scaleAdd(u, up, end);

				Q2Recycler.put(ang);
				Q2Recycler.put(diff);
				}

			// re-trace ignoring water this time
			tr = Engine.trace(waterStart, end, p.fEntity, Engine.MASK_SHOT);
			}
		}

	// send gun puff / flash
	if ((tr.fSurfaceName == null) || ((tr.fSurfaceFlags & Engine.SURF_SKY) == 0))
		{
		if ((tr.fFraction < 1.0) && (!tr.fSurfaceName.startsWith("sky")))
			{
			if (tr.fEntity.getReference() instanceof GameObject)
				((GameObject)tr.fEntity.getReference()).damage(p, p, aimDir, tr.fEndPos, tr.fPlaneNormal, damage, kick, GameObject.DAMAGE_BULLET, teImpact, obitKey); 
			}
		}

	// if went through water, determine where the end and make a bubble trail
	if (water)
		{
		Point3f pos = Q2Recycler.getPoint3f();
		Vector3f leadDir = Q2Recycler.getVector3f();
		
		leadDir.sub(tr.fEndPos, waterStart);				
		leadDir.normalize();
		pos.scaleAdd(-2, leadDir, tr.fEndPos); // = tr.fEndPos.vectorMA(-2, dir);
		
		if ((Engine.getPointContents(pos) & Engine.MASK_WATER) != 0)
			tr.fEndPos = new Point3f(pos);
		else
			tr = Engine.trace(pos, waterStart, tr.fEntity, Engine.MASK_WATER);

		pos.add(tr.fEndPos, waterStart);
		pos.scale(0.5F);

		Engine.writeByte(Engine.SVC_TEMP_ENTITY);
		Engine.writeByte(Engine.TE_BUBBLETRAIL);
		Engine.writePosition(waterStart);
		Engine.writePosition(tr.fEndPos);
		Engine.multicast(pos, Engine.MULTICAST_PVS);

		Q2Recycler.put(leadDir);
		Q2Recycler.put(pos);
		}
	}
  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);
  }