|
| 1 | +/* |
| 2 | +Copyright (c) 2024 Stephen Gold |
| 3 | +
|
| 4 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +of this software and associated documentation files (the "Software"), to deal |
| 6 | +in the Software without restriction, including without limitation the rights |
| 7 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +copies of the Software, and to permit persons to whom the Software is |
| 9 | +furnished to do so, subject to the following conditions: |
| 10 | +
|
| 11 | +The above copyright notice and this permission notice shall be included in all |
| 12 | +copies or substantial portions of the Software. |
| 13 | +
|
| 14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +SOFTWARE. |
| 21 | + */ |
| 22 | +package com.github.stephengold.joltjni; |
| 23 | + |
| 24 | +/** |
| 25 | + * An axis-aligned box. |
| 26 | + * |
| 27 | + * @author Stephen Gold [email protected] |
| 28 | + */ |
| 29 | +final public class AaBox extends JoltPhysicsObject { |
| 30 | + // ************************************************************************* |
| 31 | + // constructors |
| 32 | + |
| 33 | + /** |
| 34 | + * Instantiate a box with min=(FLT_MAX,FLT_MAX,FLT_MAX) and |
| 35 | + * max=(-FLT_MAX,-FLT_MAX,-FLT_MAX). |
| 36 | + */ |
| 37 | + public AaBox() { |
| 38 | + long boxVa = createAaBox(); |
| 39 | + setVirtualAddress(boxVa, true); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Instantiate a box with the specified minimum and maximum coordinates. |
| 44 | + * |
| 45 | + * @param minimum the desired minimum coordinates (not null, unaffected) |
| 46 | + * @param maximum the desired maximum coordinates (not null, unaffected) |
| 47 | + */ |
| 48 | + public AaBox(Vec3Arg minimum, Vec3Arg maximum) { |
| 49 | + float minX = minimum.getX(); |
| 50 | + float minY = minimum.getY(); |
| 51 | + float minZ = minimum.getZ(); |
| 52 | + float maxX = maximum.getX(); |
| 53 | + float maxY = maximum.getY(); |
| 54 | + float maxZ = maximum.getZ(); |
| 55 | + long boxVa = createAaBox(minX, minY, minZ, maxX, maxY, maxZ); |
| 56 | + setVirtualAddress(boxVa, true); |
| 57 | + } |
| 58 | + // ************************************************************************* |
| 59 | + // JoltPhysicsObject methods |
| 60 | + |
| 61 | + @Override |
| 62 | + public void close() { |
| 63 | + assert ownsNativeObject(); |
| 64 | + long virtualAddress = va(); |
| 65 | + free(virtualAddress); |
| 66 | + |
| 67 | + unassignNativeObject(); |
| 68 | + } |
| 69 | + // ************************************************************************* |
| 70 | + // native private methods |
| 71 | + |
| 72 | + native private static long createAaBox(); |
| 73 | + |
| 74 | + native private static long createAaBox(float minX, float minY, float minZ, |
| 75 | + float maxX, float maxY, float maxZ); |
| 76 | + |
| 77 | + native private static void free(long virtualAddress); |
| 78 | +} |
0 commit comments