irrlicht/tests/testVector2d.cpp
engineer_apple 2340f9b849 Changes in 1.6 TA
- PixelBlend16 and PixelBlend16_simd are working for the new rules.
	- bugfix. CLightSceneNode didn't correctly update it's attributes
	
		Lighting Linear Attenuation.	= 1.f / radius
		
		The Example loadirr files set the lightscene radius to 1000.f but
		stays on the previous default attentuation with the older radius 100 -> 1.f / 100
		so the examples looks golden-brown.
		
		Now the radius is correctly!! set to the attenuation of 1.f/1000.f because the
		file doesn't have special attenuation. and now it looks more yellow.
		can anybody show me a correct screenshot for this file;-)? Niko?
		
		Or is this behavior the default lighting?. then it would be
		a fixed constant linear attenuation of 0.01f;-). Please clearify
		For now i didn't fixed it
		
		
		I encountered this behavior because i ( burning video ) used the original radius
		for calculations and so i've found that radius != 1.f / linearAttenuation but
		in the LightSceneNode this formula was used.. confused;-)
		

	- vector template and equals tests
		as working with the test suits i cleaned the template behavior (mixed types are
		used in the templates) and added all missing special math function with their coressponding type
		I also set the equal test for s32 to behave like the f32 routine.

		The function equals always implements a weak test.		
		that means a tolerance MUST always be used if you use the equal function. default is 1.
		you can set it to zero a==b-> equals ( a, b, 0 ) but do it explicit like you have to
		for floating compare. This is important when irrlicht is going to use special hardware
		math acceleration on a per function base, like sse2, or the other way round fixpoint.
	
	- VideoDriver drawPixel
		The HW renderes are using the alpha components for blending.
		The Software Renderes and image loaders are using CImage::setPixel copy. 
		so setPixel is engaged to either blends or copy the pixel
		default: false
	- Burningvideo
		added RenderMaterial EMT_SPHERE_MAP
			pushed burningsvideo to 0.43
		added RenderMaterial EMT_REFLECTION_2_LAYER
			pushed burningsvideo to 0.44
		set	EMT_TRANSPARENT_ALPHA_CHANNEL_REF
			to use AlphaRef 0.5 like Direct3D
			
		One Note: in OpenGL there is know difference between sphere_map and reflection layer
		both using GL_TEXTURE_GEN_MODE GL_SPHERE_MAP, whereas in d3d one time using camera_normal
		on sphere and reflection on refletcion_layer.
		
		The visual difference is that on sphere map the "image is not moving" when you rotate the 
		viewer. For Buring i took the opengl visual. always moving
				

	- rename quake3 SEntity to IEntity to be confom with IShader
		even IShader and IEntity are none pure virtual interfaces
		like most irrlicht objects


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2207 dfc29bdd-3216-0410-991c-e03cc46cb475
2009-02-10 15:08:23 +00:00

135 lines
4.2 KiB
C++

// Copyright (C) 2008-2009 Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
#include "irrlicht.h"
#include <assert.h>
using namespace irr;
using namespace core;
template<class T>
static bool compareVectors(const core::vector2d<T> & compare,
const core::vector2d<T> & with)
{
if(compare != with)
{
logTestString("\nERROR: vector2d %.16f, %.16f != vector2d %.16f, %.16f\n",
(f64)compare.X, (f64)compare.Y, (f64)with.X, (f64)with.Y);
assert(compare == with);
return false;
}
return true;
}
template <class T>
static bool doTests()
{
#define COMPARE_VECTORS(compare, with)\
if(!compareVectors(compare, with)) return false;
vector2d<T> vec(5, 5);
vector2d<T> otherVec(10, 20);
if(!equals(vec.getDistanceFrom(otherVec), (T)15.8113883))
{
logTestString("vector2d::getDistanceFrom() failed\n");
assert(0);
return false;
}
vec.rotateBy(45); // Test implicit (0, 0) center
COMPARE_VECTORS(vec, vector2d<T>(0, (T)7.0710678118654755));
vec.normalize();
COMPARE_VECTORS(vec, vector2d<T>(0, (T)1.0000000461060017));
vec.set(10, 10);
vector2d<T> center(5, 5);
vec.rotateBy(-5, center);
// -5 means rotate clockwise slightly, so expect the X to increase
// slightly and the Y to decrease slightly.
COMPARE_VECTORS(vec, vector2d<T>((T)10.416752204197017, (T)9.5451947767204359));
vec.set(5, 5);
vec.normalize();
compareVectors(vec, vector2d<T>((T)0.70710681378841400, (T)0.70710681378841400));
vec.set(5, 5);
otherVec.set(10, 20);
vector2d<T> interpolated;
(void)interpolated.interpolate(vec, otherVec, 0.f);
COMPARE_VECTORS(interpolated, otherVec); // 0.f means all the second vector
(void)interpolated.interpolate(vec, otherVec, 0.25f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)8.75, (T)16.25));
(void)interpolated.interpolate(vec, otherVec, 0.75f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)6.25, (T)8.75));
(void)interpolated.interpolate(vec, otherVec, 1.f);
COMPARE_VECTORS(interpolated, vec); // 1.f means all the first vector
interpolated = vec.getInterpolated(otherVec, 0.f);
COMPARE_VECTORS(interpolated, otherVec); // 0.f means all the second vector
interpolated = vec.getInterpolated(otherVec, 0.25f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)8.75, (T)16.25));
interpolated = vec.getInterpolated(otherVec, 0.75f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)6.25, (T)8.75));
interpolated = vec.getInterpolated(otherVec, 1.f);
COMPARE_VECTORS(interpolated, vec); // 1.f means all the first vector
vector2d<T> thirdVec(20, 10);
interpolated = vec.getInterpolated_quadratic(otherVec, thirdVec, 0.f);
COMPARE_VECTORS(interpolated, vec); // 0.f means all the 1st vector
interpolated = vec.getInterpolated_quadratic(otherVec, thirdVec, 0.25f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)7.8125, (T)10.9375));
interpolated = vec.getInterpolated_quadratic(otherVec, thirdVec, 0.5f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)11.25, (T)13.75));
interpolated = vec.getInterpolated_quadratic(otherVec, thirdVec, 0.75f);
COMPARE_VECTORS(interpolated, vector2d<T>((T)15.3125, (T)13.4375));
interpolated = vec.getInterpolated_quadratic(otherVec, thirdVec, 1.f);
COMPARE_VECTORS(interpolated, thirdVec); // 1.f means all the 3rd vector
return true;
}
/** Test the functionality of vector2d<T>, particularly methods that
involve calculations done using different precision than <T>.
Note that all reference vector2d<T>s are creating using double precision
values cast to (T), as we need to test <f64>. */
bool testVector2d(void)
{
bool f32Success = doTests<f32>();
if(f32Success)
logTestString("vector2df tests passed\n\n");
else
logTestString("\n*** vector2df tests failed ***\n\n");
bool f64Success = doTests<f64>();
if(f64Success)
logTestString("vector2d<f64> tests passed\n\n");
else
logTestString("\n*** vector2d<f64> tests failed ***\n\n");
bool s32Success = doTests<s32>();
if(s32Success)
logTestString("vector2di tests passed\n\n");
else
logTestString("\n*** vector2di tests failed ***\n\n");
return f32Success && f64Success && s32Success;
}