Reader small image

You're reading from  Game Physics Cookbook

Product typeBook
Published inMar 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781787123663
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Gabor Szauer
Gabor Szauer
author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer

Right arrow

Linetest Plane


A Line segment represented by end points A and B can be parametrically expressed as follows:

S(t) = A + t(B-A) where

We can check if a line segment intersects a Plane by substituting the parametric equation of the Line into the Plane equation. If any point along the line at time t exists that satisfies the Plane equation, the Line segment and Plane intersect:

Getting ready

We are going to implement a function to test if a Line segment and a Plane intersect. This function will return a Boolean result.

How to do it…

Follow these steps to implement line testing against a plane:

  1. Declare the Linetest function in Geometry3D.h:

    bool Linetest(const Plane& plane, const Line& line);
  2. Implement the Linetest function in Geometry3D.cpp:

    bool Linetest(const Plane& plane, const Line& line) {
       vec3 ab = line.end - line.start;
    
       float nA = Dot(plane.normal, line.start);
       float nAB = Dot(plane.normal, ab);
    
       // If the line and plane are parallel, nAB will be 0
       // This will...
lock icon
The rest of the page is locked
Previous PageNext Chapter
You have been reading a chapter from
Game Physics Cookbook
Published in: Mar 2017Publisher: PacktISBN-13: 9781787123663

Author (1)

author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer