Skip to content

Commit

Permalink
Merge pull request #3 from jonaslindemann/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jonaslindemann authored Jul 27, 2022
2 parents b502fca + 8fd4c9c commit 872ec19
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 200 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.0)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/modules)

option(IVF_UI "Build user interface integration libraries." ON)
option(IVF_UI "Build user interface integration libraries." ON)
option(IVF_UI_FLTK "Build user interface integration libraries." ON)
option(IVF_UI_WIN32 "Build user interface integration libraries." OFF)
option(IVF_UI_GLUT "Build user interface integration libraries." ON)
Expand Down
53 changes: 41 additions & 12 deletions examples/bmfonts/bmfonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ivf/QuadPlane.h>
#include <ivf/SolidLine.h>
#include <ivf/BitmapFont.h>
#include <ivf/TextLabel.h>

#include <ivfimage/SgiImage.h>
#include <ivfimage/JpegImage.h>
Expand All @@ -37,6 +38,11 @@ using namespace ivf;
// Window class definition
// ------------------------------------------------------------

float random()
{
return ((double)(rand()) / (double)RAND_MAX);
}

IvfSmartPointer(ExampleWindow);

class ExampleWindow: public GlutBase {
Expand All @@ -46,6 +52,7 @@ class ExampleWindow: public GlutBase {
LightPtr m_light;

BitmapFontPtr m_font;
TextLabelPtr m_textLabel;

double m_angleX;
double m_angleY;
Expand Down Expand Up @@ -115,8 +122,29 @@ void ExampleWindow::onInit(int width, int height)
m_scene = Composite::create();

m_font = BitmapFont::create("data/fonts/white_font.fnt");
//m_font->setCamera(m_camera);
m_font->setText("Ivf++", 2.0);

m_textLabel = TextLabel::create();
m_textLabel->setFont(m_font);
m_textLabel->setText("Ivf++", 2.0);
m_textLabel->setCamera(m_camera);

auto texts = ivf::Composite::create();

for (auto i = 0; i < 20; i++)
{
auto text = TextLabel::create();

double x = 10.0 - 20.0 * random();
double y = 10.0 - 20.0 * random();
double z = 10.0 - 20.0 * random();

text->setFont(m_font);
text->setText("A");
text->setPosition(x, y, z);
text->setCamera(m_camera);
text->setBillboardType(IVF_BILLBOARD_XY);
texts->addChild(text);
}

auto quad = QuadPlane::create();
quad->setMaterial(material);
Expand All @@ -127,7 +155,8 @@ void ExampleWindow::onInit(int width, int height)

m_scene->addChild(quad);
m_scene->addChild(axis);
m_scene->addChild(m_font);
m_scene->addChild(m_textLabel);
m_scene->addChild(texts);

// Create a light

Expand Down Expand Up @@ -166,23 +195,23 @@ void ExampleWindow::onRender()
void ExampleWindow::onKeyboard(int key, int x, int y)
{
if (key=='1')
m_font->setAlignment(HorizontalAlignment::Right, VerticalAlignment::Top);
m_textLabel->setAlignment(HorizontalAlignment::Right, VerticalAlignment::Top);
if (key == '2')
m_font->setAlignment(HorizontalAlignment::Right, VerticalAlignment::Middle);
m_textLabel->setAlignment(HorizontalAlignment::Right, VerticalAlignment::Middle);
if (key == '3')
m_font->setAlignment(HorizontalAlignment::Right, VerticalAlignment::Bottom);
m_textLabel->setAlignment(HorizontalAlignment::Right, VerticalAlignment::Bottom);
if (key == '4')
m_font->setAlignment(HorizontalAlignment::Center, VerticalAlignment::Top);
m_textLabel->setAlignment(HorizontalAlignment::Center, VerticalAlignment::Top);
if (key == '5')
m_font->setAlignment(HorizontalAlignment::Center, VerticalAlignment::Middle);
m_textLabel->setAlignment(HorizontalAlignment::Center, VerticalAlignment::Middle);
if (key == '6')
m_font->setAlignment(HorizontalAlignment::Center, VerticalAlignment::Bottom);
m_textLabel->setAlignment(HorizontalAlignment::Center, VerticalAlignment::Bottom);
if (key == '7')
m_font->setAlignment(HorizontalAlignment::Left, VerticalAlignment::Top);
m_textLabel->setAlignment(HorizontalAlignment::Left, VerticalAlignment::Top);
if (key == '8')
m_font->setAlignment(HorizontalAlignment::Left, VerticalAlignment::Middle);
m_textLabel->setAlignment(HorizontalAlignment::Left, VerticalAlignment::Middle);
if (key == '9')
m_font->setAlignment(HorizontalAlignment::Left, VerticalAlignment::Bottom);
m_textLabel->setAlignment(HorizontalAlignment::Left, VerticalAlignment::Bottom);

this->redraw();
}
Expand Down
1 change: 1 addition & 0 deletions include/ivf/Billboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IvfSmartPointer(BillBoard);

#define IVF_ALIGN_CAMERA 0
#define IVF_ALIGN_VECTOR 1
#define IVF_ALIGN_NONE 2

/**
* Billboard object
Expand Down
31 changes: 5 additions & 26 deletions include/ivf/BitmapFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,31 @@ struct Charset
CharDescriptor chars[256];
};

enum class HorizontalAlignment { Left, Center, Right };
enum class VerticalAlignment {Top, Middle, Bottom };

IvfSmartPointer(BitmapFont);

class BitmapFont : public ivf::BillBoard {
class BitmapFont : public ivf::Base {
private:
Charset m_charset;
std::string m_filename;
std::string m_textureFilename;
std::string m_text;
ivf::TexturePtr m_fontTexture;
ivf::MaterialPtr m_fontMaterial;
ivf::CompositePtr m_textQuads;
float m_textWidth;
float m_textHeight;

float m_textSize;

HorizontalAlignment m_alignX;
VerticalAlignment m_alignY;
private:
void updateText();
public:
BitmapFont(const std::string filename);

IvfClassInfo("BitmapFont", Composite);
IvfClassInfo("BitmapFont", Base);

static BitmapFontPtr create(const std::string filename) { return BitmapFontPtr(new BitmapFont(filename)); }

void setFilename(const std::string filename);
std::string filename();

void setText(const std::string text, float size=1.0);
const std::string text();

void setSize(float size);
float size();
Charset& charset();

void setAlignment(HorizontalAlignment alignX, VerticalAlignment alignY = ivf::VerticalAlignment::Bottom);
ivf::Texture* texture();
ivf::Material* material();

void load();

protected:
virtual void doPreGeometry() override;
virtual void doPostGeometry() override;
};

}
1 change: 1 addition & 0 deletions include/ivf/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class IVF_API Grid : public Shape {
bool m_useOutline;
bool m_useCorners;
bool m_useAxis;
bool m_useAxisLabels;

int m_gridInterval;

Expand Down
4 changes: 4 additions & 0 deletions include/ivf/SceneBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class IVF_API SceneBase : public Shape {
bool m_multiPass;
int m_nPasses;
bool m_renderFlatShadow;
bool m_preShadow;
bool m_postShadow;
double m_shadowColor[3];

public:
Expand Down Expand Up @@ -217,6 +219,8 @@ class IVF_API SceneBase : public Shape {
void setRenderFlatShadow(bool flag);
void setShadowColor(double red, double green, double blue);

void setShadowPrePost(bool renderPre, bool renderPost);

protected:
virtual void doPostClear();
virtual void doCreateGeometry();
Expand Down
55 changes: 55 additions & 0 deletions include/ivf/TextLabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include <string>

#include <ivf/Billboard.h>
#include <ivf/Composite.h>
#include <ivf/QuadPlane.h>
#include <ivf/Texture.h>
#include <ivf/BitmapFont.h>

namespace ivf {

enum class HorizontalAlignment { Left, Center, Right };
enum class VerticalAlignment {Top, Middle, Bottom };

IvfSmartPointer(TextLabel);

class TextLabel : public ivf::BillBoard {
private:
ivf::BitmapFontPtr m_font;
std::string m_text;
ivf::CompositePtr m_textQuads;
float m_textWidth;
float m_textHeight;
float m_textSize;

HorizontalAlignment m_alignX;
VerticalAlignment m_alignY;
private:
void updateText();
void updateExistingText();
public:
TextLabel();

IvfClassInfo("TextLabel", Composite);

static TextLabelPtr create() { return TextLabelPtr(new ivf::TextLabel()); }

void setFont(ivf::BitmapFont* font);
ivf::BitmapFont* font();

void setText(const std::string text, float size=1.0);
const std::string text();

void setSize(float size);
float size();

void setAlignment(HorizontalAlignment alignX, VerticalAlignment alignY = ivf::VerticalAlignment::Bottom);

protected:
virtual void doPreGeometry() override;
virtual void doPostGeometry() override;
};

}
77 changes: 37 additions & 40 deletions src/ivf/Billboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,46 @@ BillBoard::~BillBoard()

void BillBoard::updateRotation()
{
if (m_camera!=nullptr)
{
double ex, ey, ez, e;
double ex, ey, ez, e;

switch (m_alignObject) {
case IVF_ALIGN_CAMERA:
switch (m_alignObject) {
case IVF_ALIGN_CAMERA:
if (m_camera!=nullptr)
m_camera->getForwardVector(ex, ey, ez);
break;
case IVF_ALIGN_VECTOR:
ex = m_forward[0];
ey = m_forward[1];
ez = m_forward[2];
break;
default:
break;
case IVF_ALIGN_VECTOR:
ex = m_forward[0];
ey = m_forward[1];
ez = m_forward[2];
break;
default:
if (m_camera!=nullptr)
m_camera->getForwardVector(ex, ey, ez);
break;
}

ex = -ex;
ey = -ey;
ez = -ez;

e = sqrt(pow(ex,2) + pow(ez,2));

m_angle1 = atan2(ez,ex);
m_angle2 = atan2(e,ey);

switch (m_billboardType) {
case IVF_BILLBOARD_X:
m_angle1 = M_PI/2;
break;
case IVF_BILLBOARD_Y:
m_angle2 = M_PI/2;
break;
default:
break;
}

//this->setRotationQuat(1.0, 0.0, 0.0, m_angle2*180.0/M_PI-90);
break;
}

ex = -ex;
ey = -ey;
ez = -ez;

e = sqrt(pow(ex, 2) + pow(ez, 2));

m_angle1 = atan2(ez, ex);
m_angle2 = atan2(e, ey);

switch (m_billboardType) {
case IVF_BILLBOARD_X:
m_angle1 = M_PI / 2;
break;
case IVF_BILLBOARD_Y:
m_angle2 = M_PI / 2;
break;
default:
break;
}
}

void BillBoard::setCamera(Camera *camera)
void BillBoard::setCamera(Camera* camera)
{
m_camera = camera;
}
Expand All @@ -97,7 +94,7 @@ int BillBoard::getBillboardType()

void BillBoard::doCreateGeometry()
{
if (m_camera != nullptr)
if (m_alignObject!=IVF_ALIGN_NONE)
{
this->updateRotation();
glPushMatrix();
Expand All @@ -108,7 +105,7 @@ void BillBoard::doCreateGeometry()

Composite::doCreateGeometry();

if (m_camera != nullptr)
if (m_alignObject != IVF_ALIGN_NONE)
{
glPopMatrix();
glPopMatrix();
Expand All @@ -123,7 +120,7 @@ void BillBoard::setVector(double vx, double vy, double vz)
m_forward[2] = vz;
}

void BillBoard::setVector(double *v)
void BillBoard::setVector(double* v)
{
m_forward[0] = v[0];
m_forward[1] = v[1];
Expand Down
Loading

0 comments on commit 872ec19

Please sign in to comment.