PeteCotton
 Guru
 Joined: 13/08/2020 Location: CanadaPosts: 535 |
Posted: 10:15pm 06 Oct 2024 |
|
|
|
I've been playing with the awesome 3D commands on the CMM2, but I'm having a bit of trouble understanding what's going on here.
I have a cube that starts in front of the camera and moves towards the camera (down the Z axis). After it passes through the camera, it reappears as if moving away from the camera.
Now, it's not a problem in real life, because realistically I would cull everything behind the camera before drawing, but I'm just wondering if I'm completely failing to understand the 3D camera.
Here's the code:
OPTION EXPLICIT Create3DCubeSubroutine() ' Creates a cube as object #1 DIM FLOAT z=500 ' Cube starts off 230 points away on the Z axis PAGE WRITE 1 DRAW3D CAMERA 1,300,0,0
DO z=z-2 ' Decrease Z so that cube comes towards camera CLS RGB(BLACK) PRINT "VALUE OF Z = " + STR$(Z) DRAW3D WRITE 1,0,0,z PAGE COPY 1,0 PAUSE 20 LOOP
SUB Create3DCubeSubroutine DIM FLOAT vertices(2,7)=(-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,1,-1,-1,1) DIM INTEGER facecount(5)=(4,4,4,4,4,4) DIM INTEGER faces(23)=(0,1,2,3,1,5,6,2,0,4,5,1,5,4,7,6,2,6,7,3,0,3,7,4) DIM INTEGER colours(6)=(RGB(BLUE),RGB(GREEN),RGB(RED),RGB(CYAN),RGB(RED),RGB(BLUE),RGB(YELLOW)) DIM INTEGER edge(5)=(6,6,6,6,6,6) DIM INTEGER fill(5)=(0,1,2,3,4,5) DRAW3D CREATE 1,8,6,1,vertices(),facecount(),faces(),colours(),edge(),fill() END SUB
And this is shot by shot display of what happens
It starts off fine with cube moving towards the camera (note the Blue face is facing the camera).

Getting closer still, this is working as expected - note the Z value at the top of the screen.

There is a brief moment when the camera is inside the cube at Z=0, where everything goes wonky - this is to be expected.
But then as the cube moves behind the camera, it reappears (note the Cyan side which is the rear of the cube).

And continues to vanish off into the distance
 Am I doing something incorrectly? I've read and re-read the 3D manual/notes repeatedly but can't see what I'm doing wrong.
Thanks in advance,
Pete Edited 2024-10-07 08:16 by PeteCotton |