Examples of Vector2f


Examples of net.phys2d.math.Vector2f

  public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    int count = collider.collide(contacts, bodyB, bodyA);
   
    // reverse the collision results by inverting normals
    for ( int i = 0; i < count; i++ ) {
      Vector2f vec = MathUtil.scale(contacts[i].getNormal(),-1);
      contacts[i].setNormal(vec);
    }
   
    return count;
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

   */
  public void intersect(int a, int b) {
    if ( noIntersections >= MAX_INTERSECTIONS )
      return;
   
    Vector2f startA = vertsA[a];
    Vector2f endA = vertsA[(a+1) % vertsA.length ];
    Vector2f startB = vertsB[b];
    Vector2f endB = vertsB[(b+1) % vertsB.length ];
    //TODO: reuse mathutil.intersect
    float d = (endB.y - startB.y) * (endA.x - startA.x) - (endB.x - startB.x) * (endA.y - startA.y);
   
    if ( d == 0 ) // parallel lines
      return;
   
    float uA = (endB.x - startB.x) * (startA.y - startB.y) - (endB.y - startB.y) * (startA.x - startB.x);
    uA /= d;
    float uB = (endA.x - startA.x) * (startA.y - startB.y) - (endA.y - startA.y) * (startA.x - startB.x);
    uB /= d;
   
    if ( uA < 0 || uA > 1 || uB < 0 || uB > 1 )
      return; // intersection point isn't between the start and endpoints
   
    Vector2f position = new Vector2f(
        startA.x + uA * (endA.x - startA.x),
        startA.y + uA * (endA.y - startA.y));
   
    Vector2f dist = new Vector2f(position);
    dist.sub(startA);
    float distFromVertA = dist.lengthSquared();
    dist = new Vector2f(position);
    dist.sub(startB);
    float distFromVertB = dist.lengthSquared();
   
    // z axis of 3d cross product
    float sA = (startA.x - startB.x) * (endB.y - startB.y) - (endB.x - startB.x) * (startA.y - startB.y);
   
    if ( sA > 0 ) {
View Full Code Here

Examples of net.phys2d.math.Vector2f

    int count = super.collide(contacts, boxBody, circleBody);
   
    // reverse the collision results by inverting normals
    // and projecting the results onto the circle
    for (int i=0;i<count;i++) {
      Vector2f vec = MathUtil.scale(contacts[i].getNormal(),-1);
      contacts[i].setNormal(vec);
     
      Vector2f pt = MathUtil.sub(contacts[i].getPosition(), circleBody.getPosition());
      pt.normalise();
      pt.scale(((Circle) circleBody.getShape()).getRadius());
      pt.add(circleBody.getPosition());
      contacts[i].setPosition(pt);
    }
   
    return count;
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

    if (c == 's') {   
      Vector2f[] circleVerts = new Vector2f[30];
      float[] radius = {20,10};
      for( int i = 0; i < 30; i++ ) {
        float angle = (float) (3*4 * i * Math.PI/180);
        circleVerts[i] = new Vector2f(
            (float) (Math.cos(angle) * radius[i%2]),
            (float) (Math.sin(angle) * radius[i%2]));
      }
      Polygon circlePolygon = new Polygon(circleVerts);
      newBody = new Body(circlePolygon, 4);
    } else if ( c == 'w' ) {
      newBody = new Body(new Circle(15), 2);
    } else if ( c == 'l' ) {
      newBody = new Body(new Line(0,-50,0,50), 1f);
    } else if ( c == 't' ) {
      Vector2f[] triangleVerts = {new Vector2f(-20, -20), new Vector2f(20,-20), new Vector2f(20,20)};
      ConvexPolygon trianglePolygon = new ConvexPolygon(triangleVerts);
      newBody = new Body(trianglePolygon, 3);
    } else if ( c == 'b' ) {
      newBody = new Body(new Box(20,30), 3);
    } else {
View Full Code Here

Examples of net.phys2d.math.Vector2f

      world.add(b2);
     
      bodies[i]=b2;
    }
   
    final AngleJoint aj1 = new AngleJoint(b1,bodies[0],new Vector2f(),new Vector2f(),-(float)Math.PI/9.0f,-0.0f);
    //AngleJoint aj1 = new AngleJoint(b1,bodies[0],new Vector2f(),new Vector2f(),0.0f,-0.0f);
    final DistanceJoint dj1 = new DistanceJoint(b1,bodies[0],new Vector2f(),new Vector2f(),30);
    final AngleJoint aja2 = new AngleJoint(bodies[0],b1,new Vector2f(),new Vector2f(),-(float)Math.PI/9.0f+(float)Math.PI,(float)Math.PI);
    world.add(aja2);
    world.add(dj1);
    world.add(aj1);
    for(int i=1;i<N;i++){
      final AngleJoint aj = new AngleJoint(bodies[i-1],bodies[i],new Vector2f(),new Vector2f(),-(float)Math.PI/9.0f,-0.0f);
      world.add(aj);
     
      final AngleJoint aj2 = new AngleJoint(bodies[i],bodies[i-1],new Vector2f(),new Vector2f(),-(float)Math.PI/9.0f+(float)(Math.PI+Math.sin(i/10.0f)),(float)(Math.PI+Math.sin(i/10.0f)));
      world.add(aj2);
     
      final DistanceJoint dj = new DistanceJoint(bodies[i-1],bodies[i],new Vector2f(),new Vector2f(),30);
      world.add(dj);
    }
  }
View Full Code Here

Examples of org.lwjgl.util.vector.Vector2f

          break;
      }

      System.out.println("OK");

      quadPosition = new Vector2f(100f, 100f);
      quadVelocity = new Vector2f(1.0f, 1.0f);

      texScaleX = TEXTURE_SIZE / (float)mode.getWidth();
          texScaleY = TEXTURE_SIZE / (float)mode.getHeight();
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of org.lwjgl.util.vector.Vector2f

      //find displaymode
      switchMode();
      // start of in windowed mode
      Display.create();
      glInit();
      quadPosition = new Vector2f(100f, 100f);
      quadVelocity = new Vector2f(1.0f, 1.0f);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of org.lwjgl.util.vector.Vector2f

      glInit();
      initPbuffer();

      Keyboard.create();

      quadPosition = new Vector2f(100f, 100f);
      quadVelocity = new Vector2f(1.0f, 1.0f);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of org.lwjgl.util.vector.Vector2f

                if (face.hasNormals()) {
                    Vector3f n1 = m.getNormals().get(face.getNormalIndices()[0] - 1);
                    glNormal3f(n1.x, n1.y, n1.z);
                }
                if (face.hasTextureCoordinates()) {
                    Vector2f t1 = m.getTextureCoordinates().get(face.getTextureCoordinateIndices()[0] - 1);
                    glTexCoord2f(t1.x, t1.y);
                }
                Vector3f v1 = m.getVertices().get(face.getVertexIndices()[0] - 1);
                glVertex3f(v1.x, v1.y, v1.z);
                if (face.hasNormals()) {
                    Vector3f n2 = m.getNormals().get(face.getNormalIndices()[1] - 1);
                    glNormal3f(n2.x, n2.y, n2.z);
                }
                if (face.hasTextureCoordinates()) {
                    Vector2f t2 = m.getTextureCoordinates().get(face.getTextureCoordinateIndices()[1] - 1);
                    glTexCoord2f(t2.x, t2.y);
                }
                Vector3f v2 = m.getVertices().get(face.getVertexIndices()[1] - 1);
                glVertex3f(v2.x, v2.y, v2.z);
                if (face.hasNormals()) {
                    Vector3f n3 = m.getNormals().get(face.getNormalIndices()[2] - 1);
                    glNormal3f(n3.x, n3.y, n3.z);
                }
                if (face.hasTextureCoordinates()) {
                    Vector2f t3 = m.getTextureCoordinates().get(face.getTextureCoordinateIndices()[2] - 1);
                    glTexCoord2f(t3.x, t3.y);
                }
                Vector3f v3 = m.getVertices().get(face.getVertexIndices()[2] - 1);
                glVertex3f(v3.x, v3.y, v3.z);
            }
View Full Code Here

Examples of org.lwjgl.util.vector.Vector2f

                m.getNormals().add(new Vector3f(x, y, z));
            } else if (line.startsWith("vt ")) {
                String[] xyz = line.split(" ");
                float s = Float.valueOf(xyz[1]);
                float t = Float.valueOf(xyz[2]);
                m.getTextureCoordinates().add(new Vector2f(s, t));
            } else if (line.startsWith("f ")) {
                String[] faceIndices = line.split(" ");
                int[] vertexIndicesArray = {Integer.parseInt(faceIndices[1].split("/")[0]),
                        Integer.parseInt(faceIndices[2].split("/")[0]), Integer.parseInt(faceIndices[3].split("/")[0])};
                int[] textureCoordinateIndicesArray = {-1, -1, -1};
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.