Skip to content

Bug in Mat3f.createRotationMatrix(Vec3f referenceDirection)? #19

Description

@meaten

This function returns the following output (not a rotation matrix) when it gets Vec3f(0.0f, -1.0f, 0.0f)

X Axis: 0.000, 0.000, 0.000
Y Axis: 0.000, 0.000, 0.000
Z Axis: 0.000, -1.000, 0.000

As far as I read this code, this function fails in coping with Y-axis singularity.

I think it should be the following

X Axis: 1.000, 0.000, 0.000
Y Axis: 0.000, 0.000, -1.000
Z Axis: 0.000, -1.000, 0.000

This is my implementation suggestion I wrote to fix this.

I replaced this section
`

	if (referenceDirection.y == 1.0f) {
		referenceDirection.y -= 0.0001f;
		referenceDirection.normalise();
	}

by

	if (Math.abs(referenceDirection.y) > 0.9999f) {
		rotMat.setZBasis(referenceDirection);
		rotMat.setXBasis( new Vec3f(1.0f, 0.0f, 0.0f));
		rotMat.setYBasis( Vec3f.crossProduct( rotMat.getXBasis(), rotMat.getZBasis()).normalised());
		return rotMat;
	}`

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions