//----------------------------------------------------------------------------- // Project GeometryKit // Class G3DPlane // Creator Philippe C.D. Robert // Maintainer Philippe C.D. Robert // Creation Date Thu Sep 9 11:05:08 CEST 1999 // // Copyright (c) Philippe C.D. Robert // // The GeometryKit is free software; you can redistribute it and/or modify it // under the terms of the GNU LGPL Version 2 as published by the Free // Software Foundation // // $Id: G3DPlane.h,v 1.6 2001/01/05 20:50:48 robert Exp $ //----------------------------------------------------------------------------- /* * A Plane is defined as ax+by+cz+d=0 where * * normal = (a,b,c), stored in values[0..2] * distance = d, stored in values[3] * */ #ifndef __G3DPlane_h_INCLUDE #define __G3DPlane_h_INCLUDE #import #import @class G3DTuple3f; @class G3DMatrix4f; @class G3DBox; @class G3DLine; @class G3DSphere; @interface G3DPlane : NSObject { float values[4]; } //----------------------------------------------------------------------------- // class methods //----------------------------------------------------------------------------- + (G3DPlane *)plane; + (G3DPlane *)planeWithElements:(float *)vals; + (G3DPlane *)planeWithNormal:(G3DTuple3f *)norm point:(G3DTuple3f *)tuple; + (G3DPlane *)planeWithPlane:(G3DPlane *)aPlane; //----------------------------------------------------------------------------- // init and free //----------------------------------------------------------------------------- - (id)init; // Initialises a plane with normal (0,0,1) and d = 0 - (id)initWithElements:(float *)vals; // Designated initialiser - (id)initWithNormal:(G3DTuple3f *)norm point:(G3DTuple3f *)aTuple; - (id)initWithPlane:(G3DPlane *)aPlane; //----------------------------------------------------------------------------- // math //----------------------------------------------------------------------------- - (void)shiftByDistance:(float)factor; - (BOOL)intersectsObject:(id)anObject; - (BOOL)intersectsLine:(G3DLine *)line intersection:(G3DTuple3f *)pt; - (BOOL)intersectsSphere:(G3DSphere *)sph; // Invokes the appropriate method in G3DSphere - (BOOL)intersectsPlane:(G3DPlane *)pl; // Based on the Algorithm as descibed in Graphics Gem III, P.519 - (BOOL)intersectsBox:(G3DBox *)aBox; // Invokes the appropriate method in G3DBox - (void)transform:(G3DMatrix4f *)aMatrix; // Calculates m * [n1,n2,n3,d], such as it can be used by OpenGL - (BOOL)isParallel:(G3DPlane *)aPlane; - (BOOL)isEqualToPlane:(G3DPlane *)aPlane; - (BOOL)isInHalfSpace:(G3DTuple3f *)vec; // The half space is defined by the normal of the plane - (float)distanceFromPoint:(G3DTuple3f *)aTuple; //----------------------------------------------------------------------------- // accessor methods //----------------------------------------------------------------------------- - (void)setDistance:(float)aDistance; - (float)distance; - (void)setNormal:(G3DTuple3f *)aNorm; - (G3DTuple3f *)normal; // setNormal normalises aNorm before setting it - (void)setElements:(float *)vals; - (void)getElements:(float *)vals; - (float *)elements; //----------------------------------------------------------------------------- // NSCoding //----------------------------------------------------------------------------- - (void)encodeWithCoder:(NSCoder *)aCoder; - (id)initWithCoder:(NSCoder *)aCoder; //----------------------------------------------------------------------------- // NSCopying //----------------------------------------------------------------------------- - (id)copyWithZone:(NSZone *)zone; @end extern NSString *G3DPlaneException; #endif