Commit 314d53a3 authored by hybrid's avatar hybrid

Fix billboard error which used the wrong width for top and bottom width of...

Fix billboard error which used the wrong width for top and bottom width of trapezoid billboards. The reason is the use of cross-product, which flips the vertical axis used in calculations. Properly documented in the code now, API now works as expected. Bug and fix provided by pc0de.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4030 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5cd23141
...@@ -84,6 +84,7 @@ void CBillboardSceneNode::render() ...@@ -84,6 +84,7 @@ void CBillboardSceneNode::render()
core::vector3df topHorizontal = horizontal * 0.5f * TopEdgeWidth; core::vector3df topHorizontal = horizontal * 0.5f * TopEdgeWidth;
horizontal *= 0.5f * Size.Width; horizontal *= 0.5f * Size.Width;
// pointing down!
core::vector3df vertical = horizontal.crossProduct(view); core::vector3df vertical = horizontal.crossProduct(view);
vertical.normalize(); vertical.normalize();
vertical *= 0.5f * Size.Height; vertical *= 0.5f * Size.Height;
...@@ -94,15 +95,15 @@ void CBillboardSceneNode::render() ...@@ -94,15 +95,15 @@ void CBillboardSceneNode::render()
vertices[i].Normal = view; vertices[i].Normal = view;
/* Vertices are: /* Vertices are:
3--0
| /|
|/ |
2--1 2--1
|\ |
| \|
3--0
*/ */
vertices[0].Pos = pos + topHorizontal + vertical; vertices[0].Pos = pos + horizontal + vertical;
vertices[1].Pos = pos + horizontal - vertical; vertices[1].Pos = pos + topHorizontal - vertical;
vertices[2].Pos = pos - horizontal - vertical; vertices[2].Pos = pos - topHorizontal - vertical;
vertices[3].Pos = pos - topHorizontal + vertical; vertices[3].Pos = pos - horizontal + vertical;
// draw // draw
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
using namespace irr; using namespace irr;
// Test billboards namespace
bool billboards(void) {
// Test billboard sizing
bool billboardSize(void)
{ {
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions. // Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32); IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
...@@ -106,3 +108,47 @@ bool billboards(void) ...@@ -106,3 +108,47 @@ bool billboards(void)
return result; return result;
} }
// Test billboard orientation
bool billboardOrientation(void)
{
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
assert(device);
if (!device)
return false;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager * smgr = device->getSceneManager();
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
scene::IBillboardSceneNode* bill = smgr->addBillboardSceneNode(0, core::dimension2df(40,40));
bill->setPosition(core::vector3df(0,-15,10));
bill->getMaterial(0).Lighting=false;
bill->getMaterial(0).setTexture(0, driver->getTexture("../media/fontcourier.bmp"));
bool result = false;
device->run();
driver->beginScene(true, true, video::SColor(255, 60, 60, 60));
smgr->drawAll();
driver->endScene();
result = takeScreenshotAndCompareAgainstReference(driver, "-billboardOrientation.png");
device->closeDevice();
device->run();
device->drop();
return result;
}
} // end anonymous namespace
// Test billboards
bool billboards(void)
{
bool result = billboardSize();
result &= billboardOrientation();
return result;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment