| duney (7) | |||||
|
Hi everyone, wondering if you would please be able to help me on a few things, I've got a Zbuffering assignment which I'm almost there on, but a few things are giving me problems/errors and I'd hugely appreciate if anyone could find the solution for me. I'll put each question, and then the relevant code I currently have for that section, ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 1. "Initialise the z buffer before every frame. You should initialise all the values of zbuf to zero at the start of DrawImage so that the z buffer is initialised at the start of every frame." I currently have the zbuffer array declared as double zbuf[WINDOWWIDTH][WINDOWHEIGHT]
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2. "add a z parameter to drawtrapezium. This will need to be a double. The formal parameter ( call it current_z) needs to be added to the function definition and to the prototype. Where the function is called in drawpolygon use the actual parameter poly->vert[0].z i.e. the z coordinate of polygon vertex zero. This is a 1/z value, calculated in project and copied through my versions of the clipping functions – beware if you are using your own clipping function." And also included in the same section, 3. "add the test within drawtrapezium. Just before the call to Plotpix put in an if statement comparing current_z to the value of zbuf at the point where you will be plotting. If the current_z value is larger you want to proceed with the Plotpix AND update the zbuf value to be the same as the “winning” value of current_z."
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Thanks a lot in advance to anyone who can assist me with this :-) | |||||
|
|
|||||
| jpeg (133) | |
| Not sure if this helps at all but right now you have zbuff == 0; for problem one and that won't do anything. == is the comparison whereas = sets it to 0. I don't think you can just say zbuff = 0; though since zbuff is a 2 dimensional array. You would have to iterate through and set each element to 0. | |
|
|
|
| duney (7) | |
| Still having problems, although I missed the == issue so thanks for that, but having a single = causes even more errors for me :-( | |
|
|
|
| helios (9442) | |
|
Like jpeg said, zbuff is a pointer to a matrix. You can't just set it to zero. If you do, the array becomes stray. You need to iterate through all elements to do it. | |
|
|
|
| duney (7) | |
|
I see. would you mind giving an example of this please? Thanks | |
|
|
|
| Duoas (6333) | ||||||||
Hope this helps. | ||||||||
|
Last edited on
|
||||||||
| duney (7) | |
| Thanks very much for this, I'll give it a go! | |
|
|
|