Skip to content

Commit

Permalink
Vertex: add 2 public setters
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 10, 2025
1 parent 14c2cb8 commit d2ca45b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion src/main/java/com/github/stephengold/joltjni/Vertex.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024 Stephen Gold
Copyright (c) 2024-2025 Stephen Gold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -40,6 +40,17 @@ public Vertex() {
long vertexVa = createDefault();
setVirtualAddress(vertexVa, () -> free(vertexVa));
}

/**
* Instantiate with the specified container and native object.
*
* @param container the containing object, or {@code null} if none
* @param vertexVa the virtual address of the native object to assign (not
* zero)
*/
Vertex(JoltPhysicsObject container, long vertexVa) {
super(container, vertexVa);
}
// *************************************************************************
// new methods exposed

Expand Down Expand Up @@ -98,6 +109,19 @@ public void setInvMass(float invMass) {
setInvMass(vertexVa, invMass);
}

/**
* Alter the initial location of the vertex.
*
* @param location the desired location (not null, unaffected)
*/
public void setPosition(Float3 location) {
long vertexVa = va();
float x = location.x;
float y = location.y;
float z = location.z;
setPosition(vertexVa, x, y, z);
}

/**
* Alter the initial location of the vertex.
*
Expand All @@ -111,6 +135,20 @@ public void setPosition(Vec3Arg location) {
setPosition(vertexVa, x, y, z);
}

/**
* Alter the initial velocity of the vertex.
*
* @param velocity the desired velocity (in meters per second, not null,
* unaffected)
*/
public void setVelocity(Float3 velocity) {
long vertexVa = va();
float vx = velocity.x;
float vy = velocity.y;
float vz = velocity.z;
setVelocity(vertexVa, vx, vy, vz);
}

/**
* Alter the initial velocity of the vertex.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/native/glue/v/Vertex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024 Stephen Gold
Copyright (c) 2024-2025 Stephen Gold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit d2ca45b

Please sign in to comment.