Beispiel #1
0
bool BBox::intersects(Ray r) {
    Vect orig = r.getOrigin();
    Vect dir = r.getDirection();

    float tmin = (pmin.getX() - orig.getX()) / dir.getX();
    float tmax = (pmax.getX() - orig.getX()) / dir.getX();
    if (tmin > tmax) swap(tmin, tmax);

    float tymin = (pmin.getY() - orig.getY()) / dir.getY();
    float tymax = (pmax.getY() - orig.getY()) / dir.getY();
    if (tymin > tymax) swap(tymin, tymax);

    if ((tmin > tymax) || (tymin > tmax))
        return false;

    if (tymin > tmin)
        tmin = tymin;
    if (tymax < tmax)
        tmax = tymax;

    float tzmin = (pmin.getZ() - orig.getZ()) / dir.getZ();
    float tzmax = (pmax.getZ() - orig.getZ()) / dir.getZ();
    if (tzmin > tzmax) swap(tzmin, tzmax);
    
    if ((tmin > tzmax) || (tzmin > tmax))
        return false;

    return true;
}
Beispiel #2
0
TEST(RayTracer, can_calculate_image_plane) {
    RayTracer rt(20, 10);

    Vect viewDir = rt.getViewDirection();
    CHECK_EQUAL(0, viewDir.getX());
    CHECK_EQUAL(0, viewDir.getY());
    CHECK_EQUAL(-1, viewDir.getZ());

    Vect camPos = rt.getCameraPos();
    CHECK_EQUAL(0, camPos.getX());
    CHECK_EQUAL(0, camPos.getY());
    CHECK_EQUAL(0, camPos.getZ());
    
    Vect pRight = rt.getParallelRight();
    CHECK_EQUAL(1, pRight.getX());
    CHECK_EQUAL(0, pRight.getY());
    CHECK_EQUAL(0, pRight.getZ());

    Vect pUp = rt.getParallelUp();
    CHECK_EQUAL(0, pUp.getX());
    CHECK_EQUAL(1, pUp.getY());
    CHECK_EQUAL(0, pUp.getZ());

    Vect iCtr = rt.getImageCenter();
    CHECK_EQUAL(0, iCtr.getX());
    CHECK_EQUAL(0, iCtr.getY());
    CHECK_EQUAL(-100, iCtr.getZ());
}
Beispiel #3
0
	Rectangle(const Vect<PositionUnderlyingType> & center, const Size<SizeUnderlyingType> & widthHeight,
			  InitializeFromCenterCoordinates initializationMethod) :
		vertex0((center.getX() - (widthHeight.getWidth() / 2)), (center.getY() - (widthHeight.getHeight() / 2))),
		vertex1((center.getX() + (widthHeight.getWidth() / 2)), (center.getY() - (widthHeight.getHeight() / 2))),
		vertex2((center.getX() - (widthHeight.getWidth() / 2)), (center.getY() + (widthHeight.getHeight() / 2))),
		vertex3((center.getX() + (widthHeight.getWidth() / 2)), (center.getY() + (widthHeight.getHeight() / 2))),
		center(center)
	{
		
	}
Beispiel #4
0
	Rectangle(const Vect<PositionUnderlyingType> & topLeftCorner, const Size<SizeUnderlyingType> & widthHeight,
			  InitializeFromTopLeftCoordinates initializationMethod) :
		vertex0(topLeftCorner),
		vertex1((topLeftCorner.getX() + widthHeight.getWidth()), topLeftCorner.getY()),
		vertex2(topLeftCorner.getX(), (topLeftCorner.getY() + widthHeight.getHeight())),
		vertex3((topLeftCorner.getX() + widthHeight.getWidth()), (topLeftCorner.getY() + widthHeight.getHeight())),
		center(calculateCenter())
	
	{
		
	}
Beispiel #5
0
    virtual void move(float time) {
        Vect p = getPosition();
        p += getVelocity() * time;
        if (p.getX() > screen_w) { p.setX(p.getX() - screen_w); }
        if (p.getY() > screen_h) { p.setY(p.getY() - screen_h); }
        if (p.getX() < 0) { p.setX(p.getX() + screen_w); }
        if (p.getY() < 0) { p.setY(p.getY() + screen_h); }
        setPosition(p);

        float a = getAngle();
        a += getRotation() * time;
        setAngle(a);
    }
Beispiel #6
0
TEST(RayTracer, can_compute_ray) {
    RayTracer r(2, 2, Vect(0, 0, -1), Vect(0, 1, 0));

    Ray r0 = r.computeRay(0, 0);
    Vect ctr = r0.getOrigin();
    CHECK_EQUAL(0, ctr.getX());
    CHECK_EQUAL(0, ctr.getY());
    CHECK_EQUAL(0, ctr.getZ());

    Vect dir = r0.getDirection();
    DOUBLES_EQUAL(-0.408248, dir.getX(), 0.00001);
    DOUBLES_EQUAL(-0.408248, dir.getY(), 0.00001);
    DOUBLES_EQUAL(-0.816497, dir.getZ(), 0.00001);
}
Beispiel #7
0
void can_project_and_scale_points() {
    FrameBuffer fb(500, 500);
    Vect v = Vect(0, 0, 100);
    fb.projectAndScalePoint(v);
    ASSERT_EQUAL_FLOAT(v.getX(), 250, 0.1);
    ASSERT_EQUAL_FLOAT(v.getY(), 250, 0.1);
}
Beispiel #8
0
TEST(RayTracer, ray_inits) {
    Ray r(Vect(0, 0, -1), Vect(-1, 0, 0));
    Vect o = r.getOrigin();
    Vect d = r.getDirection();
    CHECK_EQUAL(-1, o.getZ());
    CHECK_EQUAL(-1, d.getX());
}
Beispiel #9
0
TEST(RayTracer, has_normalized_vectors) {
    RayTracer rt(10, 10);
    rt.setViewDirection(Vect(3, 4, 5));
    Vect viewDir = rt.getViewDirection();
    DOUBLES_EQUAL(0.424264, viewDir.getX(), 0.0001);
    DOUBLES_EQUAL(0.565685, viewDir.getY(), 0.0001);
    DOUBLES_EQUAL(0.707106, viewDir.getZ(), 0.0001);
}
Beispiel #10
0
TEST(RayTracer, has_vertical_vector) {
    RayTracer r(20, 10);
    r.setViewDirection(Vect(0, 0, -1));
    r.setOrthogonalUp(Vect(0, 1, 0));

    Vect v = r.vertical();
    CHECK_EQUAL(0, v.getX());
    DOUBLES_EQUAL(100, v.getY(), 0.000001);
    CHECK_EQUAL(0, v.getZ());
}
Beispiel #11
0
TEST(RayTracer, has_horizontal_vector) {
    RayTracer r(30, 20);
    r.setViewDirection(Vect(0, 0, -1));
    r.setOrthogonalUp(Vect(0, 1, 0));

    Vect h = r.horizontal();
    DOUBLES_EQUAL(241.421, h.getX(), 0.001);
    CHECK_EQUAL(0, h.getY());
    CHECK_EQUAL(0, h.getZ());
}
Beispiel #12
0
void StressTest( void )
{
#if IMPLICIT_CONVERSIONS
	volatile int I_ValueX(2);
	volatile int I_ValueY(3);
	volatile int I_ValueZ(4);
	
	volatile char C_ValueX(7);
	volatile char C_ValueY(8);
	volatile char C_ValueZ(9);

    volatile double D_ValueX( 11 );
    volatile double D_ValueY( 12 );
	volatile double D_ValueZ( 13 );

#else
	volatile float I_ValueX(2);
	volatile float I_ValueY(3);
	volatile float I_ValueZ(4);

	volatile float C_ValueX(7);
	volatile float C_ValueY(8);
	volatile float C_ValueZ(9);

	volatile float D_ValueX( 11 );
	volatile float D_ValueY( 12 );
	volatile float D_ValueZ( 13 );
#endif

	// Disable warning message (simulating bad users)
#pragma warning( disable : 4244 )

	Vect A;

	A.setX( I_ValueX );
	A.setY( I_ValueY );
	A.setZ( I_ValueZ );

	Vect B( D_ValueX, I_ValueY, D_ValueZ );

	Vect C;

	C = A + B;
	
	Vect D( C );

	D.setX( D_ValueZ );

	C.setZ( I_ValueX );

	Vect E = A + B;

	A.set( I_ValueX, D_ValueY, C_ValueX );

	B = A+ B;
	C = B + E;

	E.setZ(I_ValueX );

	Vect F;

	F.setX(C_ValueX);

	Vect G( F.getX(), A.getY(), B.getZ() );
	Vect H( C.getZ(), C_ValueZ, F.getX() );

}
Beispiel #13
0
SColor::SColor(Vect v) {
    R(v.getX());
    G(v.getY());
    B(v.getZ());
}