Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: A question about how the 3D camera works
Author | Message | ||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 367 |
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 |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
For my Stellar Battle in the Seven Green Hills Zone with the 3D engine, I had to make a point of not drawing anything with a Z less than some (positive) cut off value, determined experimentally. So yes, I found some issues when objects were right up close and friendly. To speed drawing, I also don't draw anything with ABS(X) < Z. (Y was fixed at 0.) This worked for my chosen zoom factor which gave a roughly 90 degree field of view. Visit Vegipete's *Mite Library for cool programs. |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 367 |
Thanks Pete. You've confirmed that I'm not missing something fundamental. I did have logic to not draw anything out with of the field of view - but I turned it off at one point and got all sorts of weird things happening that I couldn't explain. Then I refined it down to the simple demo code that I posted above, and was worried that I had completely misunderstood the way the camera worked. It wouldn't be the first time one of my programs worked correctly and I had no idea why I had forgotten about your Stellar Battle in the Seven Green Hills Zone, I'll have to look at your source and see what else I can learn. Thank you again! |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 479 |
Hey Pete Can you post your fixed code? Maybe it can be used as base for other 3d games |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 367 |
The code above was just generated from a distilling down of my current game project. A simple way to cull on that would be to just only do the DRAW3D WRITE command if Z>5. But my full code is too messy for me to publish just yet. If I ever get it finished, it will of course be published with fully commented code. Maybe as an interim I will extract out the 3D code and publish it earlier, so others can use it. But it's not quite there yet. |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
Thwill has my code posted on his 2022 Contest Github page. Whether you'll learn much from my code is debatable. The expanded version has some commenting that may give some hints of what's going on, but much detail is lacking. Visit Vegipete's *Mite Library for cool programs. |
||||
Print this page |