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) -
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 (wRx < 0) {
if (sprite.index == debugSprite)
@ -456,12 +459,18 @@ function intRenderSprites()
// The constant below is cheesy and based on empirical observation rather than understanding.
// Sorry :/
var wX = bSgnRy * pow2_w_w(log2_w_w(wRy) - wLogDist + log2_w_w(252 / 8 / 0.44));
if (sprite.index == debugSprite)
console.log(" wRx/256=" + (wRx/256.0) + ", wRy/256=" + (wRy/256.0) + ", wSize=" + wSize + ", wX=" + wX);
if (sprite.index == debugSprite) {
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
var wSpriteTop = 32 - (wSize >> 1);
var wSpriteLeft = wX + wSpriteTop;
if (sprite.index == debugSprite)
console.log(" wX=$" + wordToHex(wX) + ", wSpriteTop=$" + wordToHex(wSpriteTop) + ", wSpriteLeft=$" + wordToHex(wSpriteLeft));
var bStartTx = 0;
if (wSpriteLeft < 0) {
if (wSpriteLeft < -wSize) {
@ -485,8 +494,12 @@ function intRenderSprites()
// Calculate the texture bump per column. Result is really an 8.8 fix-point.
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)
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)
wSpriteLeft *= 8;
@ -499,9 +512,7 @@ function intRenderSprites()
img.style.top = wSpriteTop+"px";
img.style.width = 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
// keep things at roughly the right depth.
img.style.zIndex = calcZ(wLogSize-75);
img.style.zIndex = bDepth;
}
}

View File

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

View File

@ -30,7 +30,7 @@ NUM_COLS = 63
; Useful constants
W_LOG_256 = $0800
W_LOG_65536 = $4000
W_LOG_65536 = $1000
W_LOG_VIEW_DIST = $0E3F
; Variables
@ -795,8 +795,8 @@ spriteCalc: !zone
sta wSqDist+1 ; save hi byte
; Calculate wLogDist = (log2_w_w(wSqDist) + wLog256) >> 1
txa ; hi byte in X
tya ; lo byte in A
tax ; stash hi byte in X
tya ; retrieve lo byte back to A
jsr log2_w_w ; convert to log space
tay ; set aside lo byte
txa ; work on hi byte
@ -815,7 +815,7 @@ spriteCalc: !zone
sta wLogSize
tay ; lo byte where pow2 wants it
lda #>W_LOG_VIEW_DIST ; hi byte of constant
sbc wLogDist ; minus log dist
sbc wLogDist+1 ; minus log dist
sta wLogSize+1
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)
@ -934,7 +934,7 @@ spriteCalc: !zone
sec
sbc #75
sta depth
lda wLogSize
lda wLogSize+1
sbc #0
lsr
ror depth
@ -948,7 +948,7 @@ spriteCalc: !zone
!if DEBUG { jsr .debug6 }
.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.
tya
@ -994,20 +994,23 @@ spriteCalc: !zone
+prWord wLogSqRx
+prStr : !text "wLogSqRy=",0
+prWord wLogSqRy
+crout
+prStr : !text "wSqDist=",0
+prWord wSqDist
+prStr : !text "wLogDist=",0
+prWord wLogDist
+crout
+prStr : !text "wLogSize=",0
+prWord wLogSize
+prStr : !text "wSize=",0
+prWord wSize
+crout
+prStr : !text "wSpriteTop=",0
+prWord wSpriteTop
+crout
rts
.debug5 +prStr : !text "wX=",0
+prX
+prA
+crout
+prXA
rts
.debug6 +prStr : !text "bStartTx=",0
+prByte bStartTx