Inherits DD::Image::rPrimitive.
Public Types | |
enum | EdgeMask { eMaskEdge01, eMaskEdge12, eMaskEdge20, eMaskEdgeAll } |
Public Member Functions | |
const char * | Class () |
rTriangle (const GeoInfo *info, const Primitive *p) | |
rTriangle (const rTriangle &) | |
rPrimitive * | duplicate () const |
bool | add_to_render (Scene *, PrimitiveContext *) |
bool | add_to_displacement_render (Scene *, PrimitiveContext *) |
bool | intersect (float x, float y) const |
bool | intersect (float x, float y, float *dist) const |
bool | intersect_dist_squared (float x, float y, float *dist_squared) const |
bool | intersect_scanline (float y, int &X, int &R, VArray &out, VArray &du, VArray &dv) const |
float | trace (Scene *) |
float | distance (float x, float y) const |
float | distance_squared (float x, float y) const |
void | subdivide (std::vector< rPrimitive * > &primitives, SubdivisionContext *stx) |
rPrimitiveType | getPrimitiveType () const |
float | polygonEdgeDistance (const Vector4 &P, const float mindist) const |
Public Attributes | |
VArray | v [3] |
in SCREEN coordiantes, w_normalized!!! | |
float | Ax |
float | Ay |
float | Bx |
float | By |
float | Nz |
For figuring out derivatives. | |
uint8_t | edgesmask |
triangle edge mask | |
rTriangle * | polygon |
cirular list of all triangles that define the original polygon |
Renderable triangle class, created once a projection into screen space is known. The Triangle primitive class creates one of these, and add_to_render() may then change this to 0,1, or 2 renderable triangles (depending on clipping). Other primitives such as grid will create quite a few more of these.
rTriangle::rTriangle | ( | const rTriangle & | b | ) |
Copy constructor.
bool rTriangle::add_to_render | ( | Scene * | scene, |
PrimitiveContext * | ptx | ||
) | [virtual] |
Transform this triangle into homogeneous clipping space. Add any sub-triangles to the rendering scene. There's no need to further break a triangle down unless it intersects one of the frustum planes. Lastly we apply the homogeneous division by W which applies perspective to the points and places them into NDC space(Normalized Device Coordinates). This must be done AFTER clipping to guarantee that W is always > 0.
Clip this primitive, transform it to screen space, and add it to the list of primitives to render in the Scene.
The return value is true if this was added to the list. Originally this was used to indicate clipping. However implementations are now allowed to create other rPrimitive instances and add them to the list (for clipping into multiple pieces). If false is returned, this is immediately deleted. If true is returned it is assumed that destroying the Scene list will delete the primitive.
Clip the triangle against the frustum(W) near plane. There's two possibilities: a) One vertex is outside the plane. The triangle needs one additional edge defining the plane intersection line. To keep it a triangle we interpolate both vertices to the plane, and create one additional triangle primitive:
| 1 | 1 | /\ | /\ |/ \ 0 |/ \ | \ | A \ /| \ ---> 1 |\ \ /X| \ | \ \ /XX| \ | \ \ /XXX| \ | B \ \ 0 ----|--------- 2 0 |--------- 2 | |
b) Two vertices are outside the plane, so the outside edge is simply interpolated to the plane:
1 | | /\ | | /XX\ | | /XXXX\| | /XXXXXX| ---> | /XXXXXXX|\ 1 |\ /XXXXXXXX| \ | \ /XXXXXXXXX| \ | \ 0 ----------|--- 2 0 |--- 2 | |
Implements DD::Image::rPrimitive.
References DD::Image::Scene::camera, edgesmask, DD::Image::eVelocityMotionVector, DD::Image::Scene::lens_func, DD::Image::CameraOp::projection_is_linear(), v, and DD::Image::Box3::w().
bool rTriangle::add_to_displacement_render | ( | Scene * | scene, |
PrimitiveContext * | ptx | ||
) | [virtual] |
Transform this triangle into homogeneous clipping space. And add to the displacement map list in scene
Reimplemented from DD::Image::rPrimitive.
References DD::Image::Iop::displacement_bound(), DD::Image::Scene::lens_func, and DD::Image::GeoInfo::material.
bool rTriangle::intersect | ( | float | x, |
float | y | ||
) | const [virtual] |
Intersect the screen-space projected triangle with an XY point, returning true if successful.
Implements DD::Image::rPrimitive.
References v.
Referenced by distance().
bool rTriangle::intersect | ( | float | x, |
float | y, | ||
float * | dist | ||
) | const [virtual] |
Intersect the screen-space projected triangle with an XY point. Return true it was successful, and assigns the distance to the nearest edge.
Implements DD::Image::rPrimitive.
References DD::Image::Box3::inside(), and intersect_dist_squared().
bool rTriangle::intersect_dist_squared | ( | float | x, |
float | y, | ||
float * | dist_squared | ||
) | const [virtual] |
Intersect the screen-space projected triangle with an XY point. Return true it was successful, and assigns the square of the distance to the nearest edge.
Implements DD::Image::rPrimitive.
References DD::Image::Box3::inside(), MIN(), and v.
Referenced by distance_squared(), and intersect().
bool rTriangle::intersect_scanline | ( | float | y, |
int & | X, | ||
int & | R, | ||
VArray & | out, | ||
VArray & | du, | ||
VArray & | dv | ||
) | const [virtual] |
Intersect the triangle with a scanline. Return whether it was successful, and set X and R to the left and rightmost pixels affected, and set out to the value at 0,y (ie pixel 0 of the scanline, even if outside the triangle), and set du/dv to the screen-space derivatives, such that out+x*du is the value at any pixel in the scanline.
Implements DD::Image::rPrimitive.
References fast_floor(), Nz, and v.
float rTriangle::trace | ( | Scene * | scene | ) | [virtual] |
Not implemented yet.
Implements DD::Image::rPrimitive.
float rTriangle::distance | ( | float | x, |
float | y | ||
) | const [virtual] |
Distance to the nearest edge the object in screen-space. Returns 0 or negative if inside the object.
Implements DD::Image::rPrimitive.
References DD::Image::Box3::d(), and intersect().
float rTriangle::distance_squared | ( | float | x, |
float | y | ||
) | const [virtual] |
Square of the distance to the nearest edge the object in screen-space. Returns 0 or negative if inside the object.
Implements DD::Image::rPrimitive.
References DD::Image::Box3::d(), and intersect_dist_squared().