1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module graphene.Plane; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import gobject.ObjectG; 30 private import graphene.Matrix; 31 private import graphene.Point3D; 32 private import graphene.Vec3; 33 private import graphene.Vec4; 34 private import graphene.c.functions; 35 public import graphene.c.types; 36 private import gtkd.Loader; 37 38 39 /** 40 * A 2D plane that extends infinitely in a 3D volume. 41 * 42 * The contents of the `graphene_plane_t` are private, and should not be 43 * modified directly. 44 * 45 * Since: 1.2 46 */ 47 public class Plane 48 { 49 /** the main Gtk struct */ 50 protected graphene_plane_t* graphene_plane; 51 protected bool ownedRef; 52 53 /** Get the main Gtk struct */ 54 public graphene_plane_t* getPlaneStruct(bool transferOwnership = false) 55 { 56 if (transferOwnership) 57 ownedRef = false; 58 return graphene_plane; 59 } 60 61 /** the main Gtk struct as a void* */ 62 protected void* getStruct() 63 { 64 return cast(void*)graphene_plane; 65 } 66 67 /** 68 * Sets our main struct and passes it to the parent class. 69 */ 70 public this (graphene_plane_t* graphene_plane, bool ownedRef = false) 71 { 72 this.graphene_plane = graphene_plane; 73 this.ownedRef = ownedRef; 74 } 75 76 ~this () 77 { 78 if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef ) 79 graphene_plane_free(graphene_plane); 80 } 81 82 83 /** */ 84 public static GType getType() 85 { 86 return graphene_plane_get_type(); 87 } 88 89 /** 90 * Allocates a new #graphene_plane_t structure. 91 * 92 * The contents of the returned structure are undefined. 93 * 94 * Returns: the newly allocated #graphene_plane_t. 95 * Use graphene_plane_free() to free the resources allocated by 96 * this function 97 * 98 * Since: 1.2 99 * 100 * Throws: ConstructionException GTK+ fails to create the object. 101 */ 102 public this() 103 { 104 auto __p = graphene_plane_alloc(); 105 106 if(__p is null) 107 { 108 throw new ConstructionException("null returned by alloc"); 109 } 110 111 this(cast(graphene_plane_t*) __p); 112 } 113 114 /** 115 * Computes the distance of @point from a #graphene_plane_t. 116 * 117 * Params: 118 * point = a #graphene_point3d_t 119 * 120 * Returns: the distance of the given #graphene_point3d_t from the plane 121 * 122 * Since: 1.2 123 */ 124 public float distance(Point3D point) 125 { 126 return graphene_plane_distance(graphene_plane, (point is null) ? null : point.getPoint3DStruct()); 127 } 128 129 /** 130 * Checks whether the two given #graphene_plane_t are equal. 131 * 132 * Params: 133 * b = a #graphene_plane_t 134 * 135 * Returns: `true` if the given planes are equal 136 * 137 * Since: 1.2 138 */ 139 public bool equal(Plane b) 140 { 141 return graphene_plane_equal(graphene_plane, (b is null) ? null : b.getPlaneStruct()) != 0; 142 } 143 144 /** 145 * Frees the resources allocated by graphene_plane_alloc(). 146 * 147 * Since: 1.2 148 */ 149 public void free() 150 { 151 graphene_plane_free(graphene_plane); 152 ownedRef = false; 153 } 154 155 /** 156 * Retrieves the distance along the normal vector of the 157 * given #graphene_plane_t from the origin. 158 * 159 * Returns: the constant value of the plane 160 * 161 * Since: 1.2 162 */ 163 public float getConstant() 164 { 165 return graphene_plane_get_constant(graphene_plane); 166 } 167 168 /** 169 * Retrieves the normal vector pointing towards the origin of the 170 * given #graphene_plane_t. 171 * 172 * Params: 173 * normal = return location for the normal vector 174 * 175 * Since: 1.2 176 */ 177 public void getNormal(out Vec3 normal) 178 { 179 graphene_vec3_t* outnormal = sliceNew!graphene_vec3_t(); 180 181 graphene_plane_get_normal(graphene_plane, outnormal); 182 183 normal = ObjectG.getDObject!(Vec3)(outnormal, true); 184 } 185 186 /** 187 * Initializes the given #graphene_plane_t using the given @normal vector 188 * and @constant values. 189 * 190 * Params: 191 * normal = a unit length normal vector defining the plane 192 * pointing towards the origin; if unset, we use the X axis by default 193 * constant = the distance from the origin to the plane along the 194 * normal vector; the sign determines the half-space occupied by the 195 * plane 196 * 197 * Returns: the initialized plane 198 * 199 * Since: 1.2 200 */ 201 public Plane init(Vec3 normal, float constant) 202 { 203 auto __p = graphene_plane_init(graphene_plane, (normal is null) ? null : normal.getVec3Struct(), constant); 204 205 if(__p is null) 206 { 207 return null; 208 } 209 210 return ObjectG.getDObject!(Plane)(cast(graphene_plane_t*) __p); 211 } 212 213 /** 214 * Initializes the given #graphene_plane_t using the normal 215 * vector and constant of another #graphene_plane_t. 216 * 217 * Params: 218 * src = a #graphene_plane_t 219 * 220 * Returns: the initialized plane 221 * 222 * Since: 1.2 223 */ 224 public Plane initFromPlane(Plane src) 225 { 226 auto __p = graphene_plane_init_from_plane(graphene_plane, (src is null) ? null : src.getPlaneStruct()); 227 228 if(__p is null) 229 { 230 return null; 231 } 232 233 return ObjectG.getDObject!(Plane)(cast(graphene_plane_t*) __p); 234 } 235 236 /** 237 * Initializes the given #graphene_plane_t using the given normal vector 238 * and an arbitrary co-planar point. 239 * 240 * Params: 241 * normal = a normal vector defining the plane pointing towards the origin 242 * point = a #graphene_point3d_t 243 * 244 * Returns: the initialized plane 245 * 246 * Since: 1.2 247 */ 248 public Plane initFromPoint(Vec3 normal, Point3D point) 249 { 250 auto __p = graphene_plane_init_from_point(graphene_plane, (normal is null) ? null : normal.getVec3Struct(), (point is null) ? null : point.getPoint3DStruct()); 251 252 if(__p is null) 253 { 254 return null; 255 } 256 257 return ObjectG.getDObject!(Plane)(cast(graphene_plane_t*) __p); 258 } 259 260 /** 261 * Initializes the given #graphene_plane_t using the 3 provided co-planar 262 * points. 263 * 264 * The winding order is counter-clockwise, and determines which direction 265 * the normal vector will point. 266 * 267 * Params: 268 * a = a #graphene_point3d_t 269 * b = a #graphene_point3d_t 270 * c = a #graphene_point3d_t 271 * 272 * Returns: the initialized plane 273 * 274 * Since: 1.2 275 */ 276 public Plane initFromPoints(Point3D a, Point3D b, Point3D c) 277 { 278 auto __p = graphene_plane_init_from_points(graphene_plane, (a is null) ? null : a.getPoint3DStruct(), (b is null) ? null : b.getPoint3DStruct(), (c is null) ? null : c.getPoint3DStruct()); 279 280 if(__p is null) 281 { 282 return null; 283 } 284 285 return ObjectG.getDObject!(Plane)(cast(graphene_plane_t*) __p); 286 } 287 288 /** 289 * Initializes the given #graphene_plane_t using the components of 290 * the given #graphene_vec4_t vector. 291 * 292 * Params: 293 * src = a #graphene_vec4_t containing the normal vector in its first 294 * three components, and the distance in its fourth component 295 * 296 * Returns: the initialized plane 297 * 298 * Since: 1.2 299 */ 300 public Plane initFromVec4(Vec4 src) 301 { 302 auto __p = graphene_plane_init_from_vec4(graphene_plane, (src is null) ? null : src.getVec4Struct()); 303 304 if(__p is null) 305 { 306 return null; 307 } 308 309 return ObjectG.getDObject!(Plane)(cast(graphene_plane_t*) __p); 310 } 311 312 /** 313 * Negates the normal vector and constant of a #graphene_plane_t, effectively 314 * mirroring the plane across the origin. 315 * 316 * Params: 317 * res = return location for the negated plane 318 * 319 * Since: 1.2 320 */ 321 public void negate(out Plane res) 322 { 323 graphene_plane_t* outres = sliceNew!graphene_plane_t(); 324 325 graphene_plane_negate(graphene_plane, outres); 326 327 res = ObjectG.getDObject!(Plane)(outres, true); 328 } 329 330 /** 331 * Normalizes the vector of the given #graphene_plane_t, 332 * and adjusts the constant accordingly. 333 * 334 * Params: 335 * res = return location for the normalized plane 336 * 337 * Since: 1.2 338 */ 339 public void normalize(out Plane res) 340 { 341 graphene_plane_t* outres = sliceNew!graphene_plane_t(); 342 343 graphene_plane_normalize(graphene_plane, outres); 344 345 res = ObjectG.getDObject!(Plane)(outres, true); 346 } 347 348 /** 349 * Transforms a #graphene_plane_t @p using the given @matrix 350 * and @normal_matrix. 351 * 352 * If @normal_matrix is %NULL, a transformation matrix for the plane 353 * normal will be computed from @matrix. If you are transforming 354 * multiple planes using the same @matrix it's recommended to compute 355 * the normal matrix beforehand to avoid incurring in the cost of 356 * recomputing it every time. 357 * 358 * Params: 359 * matrix = a #graphene_matrix_t 360 * normalMatrix = a #graphene_matrix_t 361 * res = the transformed plane 362 * 363 * Since: 1.10 364 */ 365 public void transform(Matrix matrix, Matrix normalMatrix, out Plane res) 366 { 367 graphene_plane_t* outres = sliceNew!graphene_plane_t(); 368 369 graphene_plane_transform(graphene_plane, (matrix is null) ? null : matrix.getMatrixStruct(), (normalMatrix is null) ? null : normalMatrix.getMatrixStruct(), outres); 370 371 res = ObjectG.getDObject!(Plane)(outres, true); 372 } 373 }