Main Menu

3D - On The Fly!

Started by Scott_Bro, October 02, 2021, 03:51:47 PM

Previous topic - Next topic

Scott_Bro

Here is a test demo of a new 3d-engine I have began. Press F1 to load map and cruise around.

Here you see the common walls and the start of sectors. I will be moving on to portals too hopefully.  I was wonding about backface removal algorithm? any ideas as I know of any object normal beyond 90 degrees is out.

Portals should also help keep the scenes smaller like it really needs occlusion culling big time.  any other suggestions I like to know how to speed it up if anyone know more.

Thanks
Scott_Bro

stevmjon

#1
hey scott

good to see a new 3D engine.

the backface algorithm is not too difficult. you need to have a 'look' vector for the camera, and then calculate the 'look' vector of the polygon face itself (this is done using cross product using 3 points from the polygon).
when you have the 2 vectors (camera & polygon face), you then calculate a dot product on these 2 vectors, and the result is you answer.

dot product :
pos = the polygon faces away from the camera so cull
zero = the polygon is 90 deg so keep/cull
neg = the polygon faces toward the camera so keep.

something to note is the cross product comes in 2 methods. left hand rule & right hand rule. you may need to use both ways to experiment to see which works.
i will write a quick small demo to show this and post when done, unless kev may already have a demo showcasing this...
i also have some images i made showing cross product calculation and also dot product calculation. i will find these and post, because it helps having image to visualise the process. posting just the calculation may not explain it enough.

 stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

stevmjon

just made up a pic explaining Dot Product.

there are 3 ways to calc dot product:
> V1 . V2       (full length vector dot full length vector)  * great for polygon face culling
> uv1 . V2        (unit vector dot full length vector)  *  great for clipping / collisions as it determines actual distance from a border
> uv1 . uv2       (unit vector dot unit vector)  *  great for keeping value between -1 to +1 for eg. apply brightness of a polygon texture

i hope this helps at least with dot product calculation.

  stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

Scott_Bro

Thanks for that!  I will be needing that at some time.
for now though I'm going to work on portals/sectors.
I'll be back later for if I run into any other questions I might need.
So Thanks again.
Scott_Bro

Scott_Bro

Hi, You all!

I'm back. Still working on sectors for the engine just started realtime rendering and ceiling and floor adjuestments lots more to be done.

I have a general question at this point that I could use some help with please.

How, Do I determine if a point is in a line loop? formula or a code fragment could help with some explaination if someone would care to assist.

Once again that formula to compute if a point is inside a line-loop.  (NOT!) to be confused about playbasic's shape commands.

Thanks again and Happy Programming!

Scottie_Bro

kevin


QuoteHow, Do I determine if a point is in a line loop? formula or a code fragment could help with some explaination if someone would care to assist.

  Steve has basically already answered this above.   Think of the triangle as a LINE and the 3rd vertex is the POINT..   


stevmjon

i am not sure what is meant by line-loop. somehow i have helped but i don't know how, lol.
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

#7
 I think he's looking to check if the point is one a line.    I did write a bunch of these functions eons ago but can't seem to locate them on the forums or the main site.  


    Point On Line / Line Hit Point /  Point Intersect Line

stevmjon

i modified the 'point on line' demo that kev made (see link in reply #7), so that is is interactive to show what the calculations are looking at.

hope you don't mind kev. i thought this will help scott so he can see on screen what is going on.

   have fun with it, stevmjon


It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

Scott_Bro

#9
Open in playbasic
press function 1 to load map
press function 12 to use arrow keys and move around

The problem I have now is look at render scene in code and see the clipping code is off# ouch!
how do I clip negative numbers pass zero and below??? (without) skewing the render???
if you shut off

If Z3D(Points) <= 0 Then Z3D(Points) = 1

You will see the unrendered view that is not complete.

I will give credit to those who help with this program. I will be certain to include the names and what they did help with.
Please help
Scott_Bro

Any ideas???
Thanks ahead of time.

kevin


stevmjon

hey scott

i fixed the skewing issue. i left notes at the top of the main.pba so you can go to the lines and see what i did.
it ended up being an easy fix. i just needed to work out where to edit the code.

if you run the game, press F1 then F12 it should work fine.

> original method was to modify the cart array every time the player moved. the issue was the value gets modified every time the player moves, so is prone to rounding errors.
> fix method was to leave the cart array as original values (from map load or map edit), and just keep track of how far the player has moved in total, and add this value to the unmodified cart array every loop.

i hope this helps, stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

Scott_Bro

Thanks for the help steve but...
That does not fix the problem if you look at

If Z3D(Points) <= 0 Then Z3D(Points) = 1 and remove this line you will see what it's missing for verts.

and by making them 1 like above it's not right! The render is not correct this way I put it there to see what I kinda should look like.
The 3D Points are forced at this point and not the correct ones like maybe z3d should be one but not x3d at this point think of it like they have crossed over to negative and I cheated just for now to give me a ruff idea.

and everything is moveing so how to clip is hard at this point.
Any help maybe, kevin could if he gets around to it hopefully or steve takeing another shoot.

go look pass the wall after the stairs and then look at stairs you will see the error of forced z3d = 1

Thanks
Scott_Bro

stevmjon

my edit1 wasn't a fix for z clipping, it was to get the objects to stay the same size when you moved past all the objects, then you turn around, walk past them all again, turn around etc. each time you turn around the objects were getting smaller, until there is only a line. i fixed this issue.

i see what you mean with the missing verts. i just tested it. i commented out the line you mentioned in post above.

so we need good old clipping. no worries i can help out there:
> method 1 : i can add a player(camera), then move player in 2D grid, then calc the 3D world from the player location using transformation stages. this way the player can interact with the 2D map, or the 3D world too.
> method 2 : leave the world set up the way it is, and i can calc the clipping from player 'angle', as the world gets moved around the center already.

just a question, is the 2D grid map there as an editor to create the 3D world only, or do you want the player to interact with the 2D grid map as well? or do you want the player to interact with the 3D world itself.

   i will get tapping on my keyboard, and see what i can do. i just need a little time as i need to understand what all the arrays are doing with the data.

        stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

Scott_Bro

Kewl!

I was trying to keep the map as an editor for level design.  I don't think I would interact with it from the player's point of view.  (but maybe that would be nice too.)
for now it's there to edit the 3d-world. I can't wait to see if you get the clipping as I am having trouble with that part.
Moving a camera sounds good but requires those matrixes your talking about.  I am moving the co-ordinates here to try and simplify.

Big thanks for the help so far Steve!

By for now,
Scott_Bro