| |
Oswald
Registered: Apr 2002 Posts: 5094 |
accurate 3d rotation
some silly questions & a lot of text here, its been ages I have done this routine and I am wondering where could I find more accuracy.
I am using the additive method to get the rotation matrix, working with 16 bit sines.
first, I wonder why have I choosen the sinetable max value to be +/- $1fff, there's no consecutive 4 adc's to have overflow over +/- $8000, still an adc / sbc pair may turn into adc/adc because of the case when substracting a negative number? :/ not sure if sine lookups may align this way. also should I round the 16 bit table or those bits will go bad anyway? (dont remember if I have rounded it, boy its been precalculated in basic in the stone ages:)
secondly, I keep adding #$40 to rotation angles in many places before looking them up in sincos tables. I suspect I am doing something wrong here, trying to turn the lookup value into cosine, while still having a label for the cosine offset. sin+$40= cosine, cosine+(angle+#$40)= ??? why ? :D or does this thing come from the sin*cos to addition theoremes?
third: if I recall right each adc/sbc introduces 1 bit error, is this true? so after 2 adc lowmost 2 bits in the 16 bit result is unusable?
fourth: flipping sign of a 2 complement 16 bit number is this correct?:
lda yxl ;*-1
eor #$ff
clc
adc #$01
sta yxl
lda yxh
eor #$ff
adc #$00
sta yxh
finally, getting a cube coordinate out of the rotation matrix, only using the HI bytes:
lda xzh ;mpp
clc
adc xyh
sec
sbc xxh
sta vertexes+0
should I rewrite this to gain accuracy including the low 8 bits?:
lda xzl
clc
adc xyl
sta templ
lda xzh
adc xyh
sta temph
...
etc
finally, rounding the final8 bits by looking at the low8 is a good idea? ie, if low8 (signless) msb is high, inc high8 bits? |
|
... 13 posts hidden. Click here to view all posts.... |
| |
The Human Code Machine
Registered: Sep 2005 Posts: 112 |
For most cases there is a much easier way of backface culling polygons from convex objects. We used this simple approach on the Amiga and I think it was also described in a german paper magazine. It was an 3D article series by Sim/Razor 1911 I think... I found the same explanation in the web: http://www.hugi.scene.org/online/coding/hugi%2016%20-%20co3d15... Point 7 describes how to do it the easy way ;) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
THCM: And then again you are at the SAM (Signed Area Method) as i described at codebase64 above the additions from JackAsser :-) Although i can't tell if his approach is faster, would be worth a proper comparison on some popular objects. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
whats in the tables tmath1&2? |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
That's the square tables for babylonian multiplication. |
| |
The Human Code Machine
Registered: Sep 2005 Posts: 112 |
Bitbreaker: Yeah, but you're not using the simple reject test. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: THCM: And then again you are at the SAM (Signed Area Method) as i described at codebase64 above the additions from JackAsser :-) Although i can't tell if his approach is faster, would be worth a proper comparison on some popular objects.
For a cube a single CMP-instruction is faster that anything else. Just bake the constants in the object. The normals are implicitly rotated since they're actually the vectors in the rotation matrix. So, simply take the values of the last row of the rotation matrix. Kinda like:
; left-side
lda rot_2_0 ;z-part of the left-side's surface normal corresponds to the z-value of the rotated world x-axis
cmp #konstant
bmi culled
Similar for the other sides of course. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: For most cases there is a much easier way of backface culling polygons from convex objects. We used this simple approach on the Amiga and I think it was also described in a german paper magazine. It was an 3D article series by Sim/Razor 1911 I think... I found the same explanation in the web: http://www.hugi.scene.org/online/coding/hugi%2016%20-%20co3d15... Point 7 describes how to do it the easy way ;)
This method is a classic. A major drawback though: Requires rotation and perspective before culling => not so good. Also it requires a strict vertex order of the faces.
The method I proposed also have drawbacks of course: static camera + static objects + requires you to rotate the surface normals. However rotating surface normals for simple objects are mostly already done implicitly by taking a deeper look at the rotation matrix.
Both methods requires no additional multiplications etc which of course is a good thing. However, most often for demo-like objects all the information in the rotation matrix together with the vertex data is enough to determine surface visibility if you just attach some constant-values to each surface which you precalc when you generate the object. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
Quote: That's the square tables for babylonian multiplication.
should made it clear in the article :) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Quote: should made it clear in the article :)
Well, the articles base on each other, as the multiplication is used also during rotation and such. But it sure wouldn't hurt to add some comments to the code, yes :-) |
| |
theWizard Account closed
Registered: Jul 2007 Posts: 109 |
3d on a 64 , driller was wrong , 3d on a c64 should be illegal mate , it just looks wrong allways has allways will. |
Previous - 1 | 2 | 3 - Next |