Features that are reckoned are working (which means the full features are WIP)

This commit is contained in:
minjaesong
2017-05-09 02:40:22 +09:00
parent 79c2025509
commit e395dc3781
3 changed files with 51 additions and 31 deletions

View File

@@ -487,7 +487,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
* Apply only if not grounded; normal force is precessed separately. * Apply only if not grounded; normal force is precessed separately.
*/ */
private fun applyGravitation() { private fun applyGravitation() {
if (!isNoSubjectToGrav) { if (!isNoSubjectToGrav && !isTouchingSide(hitbox, COLLIDING_BOTTOM)) {
//if (!isTouchingSide(hitbox, COLLIDING_BOTTOM)) { //if (!isTouchingSide(hitbox, COLLIDING_BOTTOM)) {
/** /**
* weight; gravitational force in action * weight; gravitational force in action
@@ -584,6 +584,23 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
private val binaryBranchingMax = 54 // higher = more precise; theoretical max = 54 (# of mantissa + 2) private val binaryBranchingMax = 54 // higher = more precise; theoretical max = 54 (# of mantissa + 2)
private fun displaceHitbox() { private fun displaceHitbox() {
fun debug1(wut: Any?) {
// vvvvv set it true to make debug print work
if (true) println(wut)
}
fun debug2(wut: Any?) {
// vvvvv set it true to make debug print work
if (false) println(wut)
}
fun debug3(wut: Any?) {
// vvvvv set it true to make debug print work
if (false) println(wut)
}
fun debug4(wut: Any?) {
// vvvvv set it true to make debug print work
if (false) println(wut)
}
// I kinda need these notes when I'm not caffeinated // I kinda need these notes when I'm not caffeinated
// //
// First of all: Rules // First of all: Rules
@@ -607,7 +624,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
if (externalForce.isZero) { if (externalForce.isZero) {
println("externalForce is zero") debug1("externalForce is zero")
} }
else { else {
val simulationHitbox = hitbox.clone() val simulationHitbox = hitbox.clone()
@@ -618,7 +635,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
simulationHitbox.reassign(hitbox) simulationHitbox.reassign(hitbox)
simulationHitbox.translate(getBacktrackDelta(i.toDouble() / ccdSteps)) simulationHitbox.translate(getBacktrackDelta(i.toDouble() / ccdSteps))
println("ccd $i, endY = ${simulationHitbox.endPointY}") debug2("ccd $i, endY = ${simulationHitbox.endPointY}")
if (isColliding(simulationHitbox)) { //COLLIDING_EXTRA_SIZE: doing trick so that final pos would be x.99800000 instead of y.0000000 if (isColliding(simulationHitbox)) { //COLLIDING_EXTRA_SIZE: doing trick so that final pos would be x.99800000 instead of y.0000000
ccdTick = i ccdTick = i
@@ -631,7 +648,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// I think collision detection is one pixel off -- very fucking likely // I think collision detection is one pixel off -- very fucking likely
println("ccdTick = $ccdTick, endY = ${simulationHitbox.endPointY}") debug2("ccdTick = $ccdTick, endY = ${simulationHitbox.endPointY}")
///////////////////////// /////////////////////////
@@ -656,12 +673,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
var collisionNotFound = false var collisionNotFound = false
if (ccdTick == ccdSteps) { if (ccdTick == ccdSteps) {
hitbox.translate(externalForce) hitbox.translate(externalForce)
println("no collision; endX = ${hitbox.endPointX}") debug2("no collision; endX = ${hitbox.endPointX}")
collisionNotFound = true collisionNotFound = true
} }
if (!collisionNotFound) { if (!collisionNotFound) {
println("embedding befure: ${simulationHitbox.endPointX}") debug2("embedding before: ${simulationHitbox.endPointX}")
// find no-collision point using binary search // find no-collision point using binary search
// trust me, X- and Y-axis must move simultaneously. // trust me, X- and Y-axis must move simultaneously.
@@ -678,27 +695,27 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
simulationHitbox.reassign(hitbox) simulationHitbox.reassign(hitbox)
simulationHitbox.translate(getBacktrackDelta(bmid)) simulationHitbox.translate(getBacktrackDelta(bmid))
print("bmid = $bmid, new endY: ${simulationHitbox.endPointY}") debug2("bmid = $bmid, new endY: ${simulationHitbox.endPointY}")
// set new mid // set new mid
if (isColliding(simulationHitbox)) { //COLLIDING_EXTRA_SIZE: doing trick so that final pos would be x.99800000 instead of y.0000000 if (isColliding(simulationHitbox)) { //COLLIDING_EXTRA_SIZE: doing trick so that final pos would be x.99800000 instead of y.0000000
print(", going back\n") debug2(", going back\n")
high = bmid high = bmid
} }
else { else {
print(", going forth\n") debug2(", going forth\n")
low = bmid low = bmid
} }
} }
println("binarySearch embedding: ${simulationHitbox.endPointY}") debug2("binarySearch embedding: ${simulationHitbox.endPointY}")
// force set grounded-ness // force set grounded-ness
grounded = true grounded = true
// reset walkY // reset walkY
walkY = 0.0 walkY = 0.0
println("!! grounded !!") debug1("!! grounded ${Random().nextInt(1000)}!!")
} }
@@ -713,15 +730,19 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// 3.2. edge cases: (TBA) // 3.2. edge cases: (TBA)
// test: assume hitting bottom // test: assume hitting bottom
//val roundedInteger = simulationHitbox.endPointY.div(TILE_SIZE).roundInt() * TILE_SIZE val vectorSum = externalForce + controllerMoveDelta
val displacementMainAxis = -1.0// - simulationHitbox.endPointY if (vectorSum.y > 0.0 && isTouchingSide(simulationHitbox, COLLIDING_BOTTOM)) {
val displacementSecondAxis = displacementMainAxis * externalForce.x / externalForce.y val displacementMainAxis = -1.0
val displacementSecondAxis = displacementMainAxis * externalForce.x / externalForce.y
simulationHitbox.translate(displacementSecondAxis, displacementMainAxis) simulationHitbox.translate(displacementSecondAxis, displacementMainAxis)
println("dx: $displacementSecondAxis, dy: $displacementMainAxis") debug2("dx: $displacementSecondAxis, dy: $displacementMainAxis")
}
println("externalForce: $externalForce, displacement: ${simulationHitbox - hitbox}")
debug2("externalForce: $externalForce, displacement: ${simulationHitbox - hitbox}")
//hitbox.translate(getBacktrackDelta(bmid)) //hitbox.translate(getBacktrackDelta(bmid))
hitbox.reassign(simulationHitbox) hitbox.reassign(simulationHitbox)
} }
@@ -735,7 +756,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
println("# final hitbox: $hitbox, wx: $walkX, wy: $walkY") //println("# final hitbox: $hitbox, wx: $walkX, wy: $walkY")
@@ -764,15 +785,15 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
*/ */
externalForce.x *= -elasticity externalForce.x *= -elasticity
//if (this is Controllable) walkX *= -elasticity //if (this is Controllable) walkX *= -elasticity // commented; should be managed by displaceHitbox()
//println("$this\t${externalForce.x}") //println("$this\t${externalForce.x}")
} }
private fun hitAndReflectY() { private fun hitAndReflectY() {
println("** reflY **") //println("** reflY **")
externalForce.y *= -elasticity externalForce.y *= -elasticity
//if (this is Controllable) walkY *= -elasticity //if (this is Controllable) walkY *= -elasticity // commented; should be managed by displaceHitbox()
} }
@Transient private val CEILING_HIT_ELASTICITY = 0.3 @Transient private val CEILING_HIT_ELASTICITY = 0.3
@@ -818,7 +839,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
private fun isColliding(hitbox: Hitbox): Boolean { private fun isColliding(hitbox: Hitbox): Boolean {
if (isNoCollideWorld) return false if (isNoCollideWorld) return false
// offsets will stretch and shrink detection box according to the argument // detectors are inside of the bounding box
val x1 = hitbox.posX val x1 = hitbox.posX
val x2 = hitbox.endPointX - A_PIXEL val x2 = hitbox.endPointX - A_PIXEL
val y1 = hitbox.posY val y1 = hitbox.posY
@@ -843,17 +864,16 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
val y2: Double val y2: Double
/* /*
This structure: The structure:
######## // TOP ###### // TOP
| | | |
| | | |
| | | |
######## // BOTTOM ###### // BOTTOM
for hittng-the-block-edge case
*/ */
// detectors are inside of the bounding box
if (option == COLLIDING_TOP) { if (option == COLLIDING_TOP) {
x1 = hitbox.posX x1 = hitbox.posX
x2 = hitbox.endPointX - A_PIXEL x2 = hitbox.endPointX - A_PIXEL

View File

@@ -69,7 +69,7 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun reassign(other: Hitbox) = setFromTwoPoints(other.posX, other.posY, other.endPointX, other.endPointY) fun reassign(other: Hitbox) = setFromTwoPoints(other.posX, other.posY, other.endPointX, other.endPointY)
fun translate(x: Double, y: Double) = setPosition(posX + x, posY + y) fun translate(x: Double, y: Double) = setPosition(posX + x, posY + y)
fun translate(vec: Vector2) = translate(vec.x, vec.y) fun translate(vec: Vector2?) = if (vec != null) translate(vec.x, vec.y) else this
fun setPosition(x1: Double, y1: Double): Hitbox { fun setPosition(x1: Double, y1: Double): Hitbox {
hitboxStart = Point2d(x1, y1) hitboxStart = Point2d(x1, y1)

View File

@@ -366,8 +366,8 @@ class Vector2 {
* * * *
* @return [Vector2] this vector * @return [Vector2] this vector
*/ */
operator fun plus(vector: Vector2): Vector2 { operator fun plus(vector: Vector2?): Vector2 {
return Vector2(this.x + vector.x, this.y + vector.y) return Vector2(this.x + (vector?.x ?: 0.0), this.y + (vector?.y ?: 0.0))
} }
operator fun plusAssign(vector: Vector2) { operator fun plusAssign(vector: Vector2) {