All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.almasb.fxgl.physics.EdgeCallback.kt Maven / Gradle / Ivy

There is a newer version: 21.1
Show newest version
/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB ([email protected]).
 * See LICENSE for details.
 */

package com.almasb.fxgl.physics

import com.almasb.fxgl.core.math.Vec2
import com.almasb.fxgl.physics.box2d.callbacks.RayCastCallback
import com.almasb.fxgl.physics.box2d.dynamics.Fixture

/**
 *
 *
 * @author Almas Baimagambetov ([email protected])
 */
class EdgeCallback : RayCastCallback {

    var fixture: Fixture? = null
        private set

    var point: Vec2? = null
        private set

    var bestFraction = 1.0f
        private set

    override fun reportFixture(fixture: Fixture, point: Vec2, normal: Vec2?, fraction: Float): Float {
        val e = fixture.body.entity
        if (e.getComponent(PhysicsComponent::class.java).isRaycastIgnored)
            return 1.0f

        if (fraction < bestFraction) {
            this.fixture = fixture
            this.point = point.copy();
            bestFraction = fraction
        }

        return bestFraction
    }

    fun reset() {
        fixture = null
        point = null
        bestFraction = 1.0f
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy