## A+B+C+D=0 from vector + dist

Discuss programming topics for the various GPL'd game engine sources.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

### A+B+C+D=0 from vector + dist

How can I get the A+B+C+D=0 plane formula from a Quake mplane_t normal and dist?

I am assuming the mplane_t normal vectors are perpendicular to the plane as one would expect.
The night is young. How else can I annoy the world before sunsrise? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

### Re: A+B+C+D=0 from vector + dist

A+B+C= -D ?
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

### Re: A+B+C+D=0 from vector + dist

its best expressed as A*x + B*y + C*z - D = 0

some useful formulas:
distfromplane = DotProduct (plane->normal, point) - plane->dist;
plane->dist = DotProduct(plane->normal, pointonplane);
pointonplane = point - (distfromplane*plane->normal);
isinfront = distfromplane>0;
isbehind = distfromplane<0;
isfloatingpointprecisionmiraclethatyouhavetosomehowrollintoonesideyetstillallowsplayerstofallthroughcracks = distfromplane==0;

note that the distance is negated relative to more standard plane notation. in mathematics, the plane is generally two-sided. in quake, the normal faces directly forwards into empty space (unless the surface has SURF_PLANEBACK set, in which case the normal faces backwards - all 4 values are logically negated (or in the case of nodes, the two children are pre-swapped, avoiding the need for the engine to do anything special). note that the plane normals in a quake bsp are arranged to be primarily positive, reducing the total number of planes needed, and facilitating axial lookups).
for surfaces, the two tangents are normally available via the texture vector values, but note that these vectors are not kept strictly perpedicular to the normal, nor are they always normalized. because quake is weird and has annoying texture mapping, as well as texture scaling.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

### Re: A+B+C+D=0 from vector + dist

Thanks for info on the weirdnesses, especially since that information can only be known from experience and no one finds surprises any fun.

I spotted a couple of these in txqbsp.
Spike wrote:pointonplane = point - (distfromplane*plane->normal);
I'm trying to do the opposite of that and draw the planes.

If I "cheated" I could use VectorVectors (like AngleVectors, except uses vectors) on a plane normal to get the side and up and then do some extra work to get a couple of points and use the 3 points to plane formula.

But that seems like a ton of calculations for something simple.

It seems like something intuitive and simple should be able to take the plane normal and get the A*x + B*y + C*z - D = 0.
The night is young. How else can I annoy the world before sunsrise? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

### Re: A+B+C+D=0 from vector + dist

the problem with drawing a plane is that a plane is infinitely long.

if you make a guess at a tangent (rotate the axis or just hardcode something), you can crossproduct it with the normal and normalize for a real tangent. and then do it again for some bitangent too. of course, these vectors have no relation to any texturing, but hey...
then you can generate a quad by moving '0 0 0' along the plane's normal onto the plane then extend sideways to find your four points.

alternatively you can figure out which axis is the most significant for the plane, pick a set of 4 points aligned on that axis, and then push them to match the plane.

if you're drawing a brush, once you have a quad you can then clip that quad by the other planes (retaining only the stuff on the inside of the brush). the resulting clipped polygon is your brush's face.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

### Re: A+B+C+D=0 from vector + dist

Just want to say thanks to Spike for help with these kinds of things over the years.

I did some plane/point tests today and this reminded me of how I struggled with this kind of thing in the past.
The night is young. How else can I annoy the world before sunsrise? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

### Re: A+B+C+D=0 from vector + dist

Baker wrote:Just want to say thanks to Spike for help with these kinds of things over the years.
Spike is the pillar of this forum Practically everything of the very few things I know about programming is thanks to him.

Plus I always admire your study on Quake engine, Baker. Did you start learning C programming with the classic "rearrange my cd albums in alphabetically order" learning program or did you start tinkering with Quake engine as your first experience? I'm curious about it
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

### Re: A+B+C+D=0 from vector + dist

toneddu2000 wrote:Plus I always admire your study on Quake engine, Baker. Did you start learning C programming with the classic "rearrange my cd albums in alphabetically order" learning program or did you start tinkering with Quake engine as your first experience? I'm curious about it
I had an interest in C before interacting with mh or Spike or compiling an engine.

But I had assumed C was an unknowable language.

mh ended up prodding me quite a bit to engine code when I asked generic "engine what-ifs" at arm's length. And Spike always provided detailed answers I often would not immediately understand but may later re-read and understand.

Around 2011, an odd realization occurred to me. I knew C. Then I realized not only did I know C, but I knew C better than 80% of the people who claim to know C.

Then I was forced to realize the paradox that I had considered learning C impossible and that I was better than 80% of people that "know C".

Interesting? Well ... even now I feel if I think about that too hard I might accidentally unwind a causality paradox in the fabric of the universe that will destroy everything ... so I don't.

But yeah, fucked up for sure. How the fuck did that happen?

Decent minds don't want to know!

That being said, I would not know C if it were not for mh and Spike. And even more fucked up that I created "Quakespasm source base 0" before completely knowing how to code C (yeah, Quakespasm is not a fork of FitzQuake but of precisely of Baker FitzQuake 0.95 which I wrote in 6 hours to positively tweak Spirit by making a Linux version despite not having Linux, haha!). Let alone wrote modern ProQuake before knowing C with bits I picked up here and there and sheer determination.

(next topic before we cause universe to explode! It still makes no sense! We are making the Elder Gods very angry by discussing this inconsistency and right now I can tell I have mad them real, real mad If I say one more sentence, surely a lavaball will be hurled in my general direction by angry Chthon)
The night is young. How else can I annoy the world before sunsrise? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

### Re: A+B+C+D=0 from vector + dist

Baker wrote: And Spike always provided detailed answers I often would not immediately understand but may later re-read and understand.
LOL! That happened to me the same way!(but with quakeC, instead!). Spike is like a philosopher: his words are never quite understandable the first time you hear them!
Baker wrote: That being said, I would not know C if it were not for mh and Spike. And even more fucked up that I created "Quakespasm source base 0" before completely knowing how to code C (yeah, Quakespasm is not a fork of FitzQuake but of precisely of Baker FitzQuake 0.95 which I wrote in 6 hours to positively tweak Spirit by making a Linux version despite not having Linux, haha!)
Wait a minute.. Are you the author of QuakeSpasm?!?
Baker wrote: (next topic before we cause universe to explode! It still makes no sense! We are making the Elder Gods very angry by discussing this inconsistency and right now I can tell I have mad them real, real mad If I say one more sentence, surely a lavaball will be hurled in my general direction by angry Chthon)
Meadow Fun!! - my first commercial game, made with FTEQW game engine