Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Support / GLB
« Last post by AGP on November 14, 2023, 09:39:01 am »
Egon, I've been stuck for six months on the very last step of importing a GLB model. When I try to animate the (otherwise perfect) model, it gets all messed up. I'm assuming the skeletal calculations are accurate, so could you please verify that this Keyframe class is accurately converting between the Glb coordinate system and jpct's?

Code: [Select]
class Keyframe {
    private double time;
    private Matrix transform;

    public Keyframe(double time, Matrix transform) {
        this.time = time;

        // Normalize the rotation component of the transform
        Quaternion rotation = new Quaternion(transform); // Extracts the rotational component
        rotation.normalize();
        Matrix rotationMatrix = rotation.toMatrix();

        // Adjust the transform to the jPCT coordinate system
        this.transform = adjustToJpctCoordinateSystem(rotationMatrix);

        // Extract and reset translation
        SimpleVector translation = extractTranslation(transform);
        resetTranslation(transform);

        // Extract, check, and apply uniform scale
        SimpleVector scale = extractScale(transform);
        if (!isUniformScale(scale)) {
            scale = new SimpleVector(1f, 1f, 1f); // (1, 1, 1) Use uniform scale if it's not uniform
        }
        Utilities.setScale(this.transform, scale);

        // Combine rotation and scale, reapply translation
        this.transform = combineTransforms(translation, this.transform, scale);
    }
    // Method to adjust a transformation matrix to jPCT's coordinate system
    private Matrix adjustToJpctCoordinateSystem(Matrix transform) {
        Matrix adjustedMatrix = new Matrix(transform);

        // Flip the Y-axis
        adjustedMatrix.set(1, 0, -adjustedMatrix.get(1, 0));
        adjustedMatrix.set(1, 1, -adjustedMatrix.get(1, 1));
        adjustedMatrix.set(1, 2, -adjustedMatrix.get(1, 2));
        // If there's translation on Y-axis, flip it as well
        adjustedMatrix.set(1, 3, -adjustedMatrix.get(1, 3));

        // Flip the Z-axis
        adjustedMatrix.set(2, 0, -adjustedMatrix.get(2, 0));
        adjustedMatrix.set(2, 1, -adjustedMatrix.get(2, 1));
        adjustedMatrix.set(2, 2, -adjustedMatrix.get(2, 2));
        // If there's translation on Z-axis, flip it as well
        adjustedMatrix.set(2, 3, -adjustedMatrix.get(2, 3));

        return adjustedMatrix;
    }
    public double getTime() {
       return time;
    }
    // Extract the translation component from a transformation matrix
    private SimpleVector extractTranslation(Matrix transform) {
        return new SimpleVector(transform.get(3, 0), transform.get(3, 1), transform.get(3, 2));
    }
    public Matrix getTransform() {
       return transform;
    }
    // Reset the translation component of a transformation matrix to zero
    private void resetTranslation(Matrix transform) {
        transform.set(3, 0, 0);
        transform.set(3, 1, 0);
        transform.set(3, 2, 0);
    }
    // Helper method to extract scale from a transformation matrix
    private SimpleVector extractScale(Matrix transform) {
       // Assuming the scale is represented by the length of the axis vectors in the matrix
       SimpleVector scaleX = new SimpleVector(transform.get(0, 0), transform.get(1, 0), transform.get(2, 0));
       SimpleVector scaleY = new SimpleVector(transform.get(0, 1), transform.get(1, 1), transform.get(2, 1));
       SimpleVector scaleZ = new SimpleVector(transform.get(0, 2), transform.get(1, 2), transform.get(2, 2));

       return new SimpleVector(scaleX.length(), scaleY.length(), scaleZ.length());
    }
    // Combine the translation, rotation, and scale into a single transformation matrix
    private Matrix combineTransforms(SimpleVector translation, Matrix rotation, SimpleVector scale) {
        Matrix scaleMatrix = new Matrix();
        scaleMatrix.setIdentity();
        Utilities.setScale(scaleMatrix, scale);

        Matrix combined = new Matrix();
        combined.setIdentity();
        combined.matMul(rotation);
        combined.matMul(scaleMatrix);
        combined.translate(translation);

        return combined;
    }

    // Helper method to check if the scale is uniform
    private boolean isUniformScale(SimpleVector scale) {
       // Check if all components are the same within a small epsilon to account for floating-point precision
       final float epsilon = 0.0001f;
       return Math.abs(scale.x - scale.y) < epsilon && Math.abs(scale.y - scale.z) < epsilon;
    }

    // Method to apply scale to a transformation matrix
    private void applyScaleToTransform(Matrix transform, SimpleVector scale) {
       // Reset the scale component of the matrix to 1
       for (int i = 0; i < 3; i++) {
          float length = new SimpleVector(transform.get(0, i), transform.get(1, i), transform.get(2, i)).length();
          if (length != 0) { // Avoid division by zero
              transform.set(0, i, transform.get(0, i) / length);
              transform.set(1, i, transform.get(1, i) / length);
              transform.set(2, i, transform.get(2, i) / length);
          }
       }

       // Create a scale matrix
       Matrix scaleMatrix = new Matrix();
       scaleMatrix.setIdentity(); // Start with an identity matrix
       scaleMatrix.set(0, 0, scale.x);
       scaleMatrix.set(1, 1, scale.y);
       scaleMatrix.set(2, 2, scale.z);

       // Apply scale by multiplying the existing transform with the scale matrix
       transform.matMul(scaleMatrix);
    }
}
22
Support / Re: Sorting
« Last post by EgonOlsen on September 11, 2023, 07:42:41 am »
Sorry for the late reply...not sure on what metric to sort such a thing, though. As you've mentioned, it doesn't seem to be a list. And a tree would most likely reflect the parent-child relationship.
23
Support / Re: blitting - rotated ? subtractive ?
« Last post by AeroShark333 on August 28, 2023, 09:43:39 pm »
I think both are achievable using some workarounds.
The 90° rotated texture could be done using 3 ways:
1st: load the texture's bitmap 90° rotated
2nd: use Overlay to rotate the texture layer
3rd: use a blitting shader to draw your texture 90° rotated

For the subtractive color, I believe you'd need to use a blitting shader too

I'm not sure if a RenderTexture is needed for a blitting shader to work
24
Support / blitting - rotated ? subtractive ?
« Last post by MichaelJPCT on August 27, 2023, 09:04:18 am »
i wish blitting can be 90 degree rotated and can be subtractive in color.
rotated blitting can be used to mimic the rotation of screen without setting it from Android , and without using different textures.
subtractive color is easier to achieve dark text on light color background, without using different textures. ( i currently use textures with white text on black background and no alpha, additive makes the text look good on dark background)
are these possible?
25
Support / Re: framebuffer.getpixels and screen recorder
« Last post by MichaelJPCT on August 27, 2023, 08:41:26 am »
i think it uses the video encode/decode processor to do the encoding in vram then transfer the data stream to system ram/network/storage, just like recording video from physical camera.
26
Support / Sorting
« Last post by AGP on August 25, 2023, 09:21:05 pm »
This is more of a programming question than a jpct question. But since it's for sorting the bones I'm importing off of GLB in jpct, this is as good a place as any to ask it. So I'm writing a 2d skeleton viewer. Each bone knows its parent, and that's about all the information I have on them. Since I know it's a bipedal skeleton generated with Mixamo, I know the skeleton's shape. All I need is to sort the bones and draw them out. I'm doing this to verify that the parent/child relationship is accurate. What's the best way to run through the 2d List<Bone> and produce a sorted array? Now that I asked the question I realize that it's not a linear list, it's a tree. Any ideas?
27
Support / Re: framebuffer.getpixels and screen recorder
« Last post by EgonOlsen on August 25, 2023, 05:38:29 pm »
Not sure what the screen recorder does. Maybe the built-in video encoder can encode screen content directly? No idea...getPixels() is as slow as OpenGL ES. Plus the conversion into jPCT-AE internal format, which requires some byte flipping.
28
Support / framebuffer.getpixels and screen recorder
« Last post by MichaelJPCT on August 25, 2023, 09:32:01 am »
i have an A53@2.3G + mali T830 device and used the screen recorder built in the Android7 system. i get almost 30fps video recording my 3D app. (res 1920x1080)
that means Android can read the screen into system RAM at high rate. but the image was produced in GPU. does that mean there is a faster way than fb.getPixels ?
29
Projects / Re: my project - Vehicle Simulation
« Last post by MichaelJPCT on August 10, 2023, 05:47:36 pm »
Thanks.
about the controls, you need to spend some time in the QUICK START and USER CONTROL chapters in the User Manual, just pay attention to the phase TOUCH UI.
or, if you have some teenager kids, let them read the User Manual and learn to fly, they can show it to you soon.
30
Projects / Re: my project - Vehicle Simulation
« Last post by EgonOlsen on August 10, 2023, 11:34:51 am »
This is an impressive piece of work. I've no idea how to control my plane and I crashed it into the ground, but it's cool nonetheless.
Pages: 1 2 [3] 4 5 ... 10