Math for first sprite finally generating all the right numbers.

This commit is contained in:
Martin Haye 2014-05-22 07:50:26 -07:00
parent 933fd769e7
commit 3c1aa135f2
3 changed files with 31 additions and 17 deletions

View File

@ -423,6 +423,9 @@ function intRenderSprites()
var wRx = bSgnDx*bSgnCosT*pow2_w_w(wLogDx + wLogCosT) - var wRx = bSgnDx*bSgnCosT*pow2_w_w(wLogDx + wLogCosT) -
bSgnDy*bSgnSinT*pow2_w_w(wLogDy + wLogSinT); bSgnDy*bSgnSinT*pow2_w_w(wLogDy + wLogSinT);
if (sprite.index == debugSprite)
console.log(" wRx=$" + wordToHex(wRx));
// If sprite is behind the viewer, skip it. // If sprite is behind the viewer, skip it.
if (wRx < 0) { if (wRx < 0) {
if (sprite.index == debugSprite) if (sprite.index == debugSprite)
@ -456,12 +459,18 @@ function intRenderSprites()
// The constant below is cheesy and based on empirical observation rather than understanding. // The constant below is cheesy and based on empirical observation rather than understanding.
// Sorry :/ // Sorry :/
var wX = bSgnRy * pow2_w_w(log2_w_w(wRy) - wLogDist + log2_w_w(252 / 8 / 0.44)); var wX = bSgnRy * pow2_w_w(log2_w_w(wRy) - wLogDist + log2_w_w(252 / 8 / 0.44));
if (sprite.index == debugSprite) if (sprite.index == debugSprite) {
console.log(" wRx/256=" + (wRx/256.0) + ", wRy/256=" + (wRy/256.0) + ", wSize=" + wSize + ", wX=" + wX); console.log(" wRy=$" + wordToHex(wRy) + ", wSqDist=$" + wordToHex(wSqDist) +
", wLogDist=$" + wordToHex(wLogDist) + ", wLogSize=$" + wordToHex(wLogSize) +
", wSize=$" + wordToHex(wSize));
//console.log(" wRx/256=" + (wRx/256.0) + ", wRy/256=" + (wRy/256.0) + ", wSize=" + wSize + ", wX=" + wX);
}
// If no pixels on screen, skip it // If no pixels on screen, skip it
var wSpriteTop = 32 - (wSize >> 1); var wSpriteTop = 32 - (wSize >> 1);
var wSpriteLeft = wX + wSpriteTop; var wSpriteLeft = wX + wSpriteTop;
if (sprite.index == debugSprite)
console.log(" wX=$" + wordToHex(wX) + ", wSpriteTop=$" + wordToHex(wSpriteTop) + ", wSpriteLeft=$" + wordToHex(wSpriteLeft));
var bStartTx = 0; var bStartTx = 0;
if (wSpriteLeft < 0) { if (wSpriteLeft < 0) {
if (wSpriteLeft < -wSize) { if (wSpriteLeft < -wSize) {
@ -485,8 +494,12 @@ function intRenderSprites()
// Calculate the texture bump per column. Result is really an 8.8 fix-point. // Calculate the texture bump per column. Result is really an 8.8 fix-point.
var wTxColBump = pow2_w_w(wLog65536 - wLogSize); var wTxColBump = pow2_w_w(wLog65536 - wLogSize);
// Calculate the depth index for blending with walls. The constant below is cheesy and
// I'm not sure why it's needed. But it seems to keep things at roughly the right depth.
var bDepth = calcZ(wLogSize-75);
if (sprite.index == debugSprite) if (sprite.index == debugSprite)
console.log(" bStartTx=" + bStartTx + ", wTxColBump=" + wTxColBump); console.log(" bStartTx=$" + byteToHex(bStartTx) + ", wTxColBump=$" + wordToHex(wTxColBump) + ", bDepth=$" + byteToHex(bDepth));
// Adjust from Apple II coordinates to PC coords (we render 8 pixels for each 1 Apple pix) // Adjust from Apple II coordinates to PC coords (we render 8 pixels for each 1 Apple pix)
wSpriteLeft *= 8; wSpriteLeft *= 8;
@ -499,9 +512,7 @@ function intRenderSprites()
img.style.top = wSpriteTop+"px"; img.style.top = wSpriteTop+"px";
img.style.width = wSize + "px"; img.style.width = wSize + "px";
img.style.height = wSize + "px"; img.style.height = wSize + "px";
// The constant below is cheesy and I'm not sure why it's needed. But it seems to img.style.zIndex = bDepth;
// keep things at roughly the right depth.
img.style.zIndex = calcZ(wLogSize-75);
} }
} }

View File

@ -77,8 +77,8 @@ wSqDist = $AA
wLogDist = $AC wLogDist = $AC
wLogSize = $AE wLogSize = $AE
wSize = $B0 wSize = $B0
wSpriteTop = $B0 wSpriteTop = $B2
wSpriteLeft = $B2 wSpriteLeft = $B4
;--------------------------------- ;---------------------------------
; The following are in aux mem... ; The following are in aux mem...

View File

@ -30,7 +30,7 @@ NUM_COLS = 63
; Useful constants ; Useful constants
W_LOG_256 = $0800 W_LOG_256 = $0800
W_LOG_65536 = $4000 W_LOG_65536 = $1000
W_LOG_VIEW_DIST = $0E3F W_LOG_VIEW_DIST = $0E3F
; Variables ; Variables
@ -795,8 +795,8 @@ spriteCalc: !zone
sta wSqDist+1 ; save hi byte sta wSqDist+1 ; save hi byte
; Calculate wLogDist = (log2_w_w(wSqDist) + wLog256) >> 1 ; Calculate wLogDist = (log2_w_w(wSqDist) + wLog256) >> 1
txa ; hi byte in X tax ; stash hi byte in X
tya ; lo byte in A tya ; retrieve lo byte back to A
jsr log2_w_w ; convert to log space jsr log2_w_w ; convert to log space
tay ; set aside lo byte tay ; set aside lo byte
txa ; work on hi byte txa ; work on hi byte
@ -815,7 +815,7 @@ spriteCalc: !zone
sta wLogSize sta wLogSize
tay ; lo byte where pow2 wants it tay ; lo byte where pow2 wants it
lda #>W_LOG_VIEW_DIST ; hi byte of constant lda #>W_LOG_VIEW_DIST ; hi byte of constant
sbc wLogDist ; minus log dist sbc wLogDist+1 ; minus log dist
sta wLogSize+1 sta wLogSize+1
tax ; hi byte where pow2 wants it tax ; hi byte where pow2 wants it
jsr pow2_w_w ; get back from log space to normal space (in: Y=lo,X=hi, out: A=lo,X=hi) jsr pow2_w_w ; get back from log space to normal space (in: Y=lo,X=hi, out: A=lo,X=hi)
@ -934,7 +934,7 @@ spriteCalc: !zone
sec sec
sbc #75 sbc #75
sta depth sta depth
lda wLogSize lda wLogSize+1
sbc #0 sbc #0
lsr lsr
ror depth ror depth
@ -948,7 +948,7 @@ spriteCalc: !zone
!if DEBUG { jsr .debug6 } !if DEBUG { jsr .debug6 }
.draw ; Okay, I think we're all done with calculations for this sprite. .draw ; Okay, I think we're all done with calculations for this sprite.
brk ; would draw sprite here rts ; would draw sprite here
.negYX: ; subroutine to negate value in Y=lo,X=hi. .negYX: ; subroutine to negate value in Y=lo,X=hi.
tya tya
@ -994,20 +994,23 @@ spriteCalc: !zone
+prWord wLogSqRx +prWord wLogSqRx
+prStr : !text "wLogSqRy=",0 +prStr : !text "wLogSqRy=",0
+prWord wLogSqRy +prWord wLogSqRy
+crout
+prStr : !text "wSqDist=",0 +prStr : !text "wSqDist=",0
+prWord wSqDist +prWord wSqDist
+prStr : !text "wLogDist=",0
+prWord wLogDist
+crout
+prStr : !text "wLogSize=",0 +prStr : !text "wLogSize=",0
+prWord wLogSize +prWord wLogSize
+prStr : !text "wSize=",0 +prStr : !text "wSize=",0
+prWord wSize +prWord wSize
+crout
+prStr : !text "wSpriteTop=",0 +prStr : !text "wSpriteTop=",0
+prWord wSpriteTop +prWord wSpriteTop
+crout +crout
rts rts
.debug5 +prStr : !text "wX=",0 .debug5 +prStr : !text "wX=",0
+prX +prXA
+prA
+crout
rts rts
.debug6 +prStr : !text "bStartTx=",0 .debug6 +prStr : !text "bStartTx=",0
+prByte bStartTx +prByte bStartTx