Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-29 13:37:16 +0000
committerStijn Buys <ingar@osirion.org>2010-11-29 13:37:16 +0000
commit409d3ce47d8a4d48947c7b19fc2460fd801b742c (patch)
tree3a6a029bcd1041a9bd88f8868bf11372c91ac5a7 /src
parenta7808ebdf39b549f4e0df38e6d897caa2dbb24bd (diff)
Added 'testmodel' function, enabled autoscaling on ui::ModelView
Diffstat (limited to 'src')
-rw-r--r--src/client/Makefile.am60
-rw-r--r--src/client/client.cc49
-rw-r--r--src/client/client.h9
-rw-r--r--src/client/testmodelview.cc114
-rw-r--r--src/client/testmodelview.h52
-rw-r--r--src/render/camera.cc1
-rw-r--r--src/render/draw.cc50
-rw-r--r--src/render/draw.h3
-rw-r--r--src/render/state.cc19
-rw-r--r--src/render/state.h2
-rwxr-xr-xsrc/ui/modelview.cc24
-rwxr-xr-xsrc/ui/modelview.h13
12 files changed, 348 insertions, 48 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index d9ca552..c6d0ada 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -8,15 +8,57 @@ noinst_LTLIBRARIES = libclient.la
endif
-noinst_HEADERS = action.h chat.h client.h clientext.h hud.h entitymenu.h \
- input.h inventorylistview.h inventory.h joystick.h key.h keyboard.h map.h notifications.h soundext.h \
- targets.h video.h infowidget.h playerview.h worldview.h trademenu.h buymenu.h \
- targeticonbutton.h
-
-libclient_la_SOURCES = action.cc buymenu.cc chat.cc client.cc clientext.cc \
- entitymenu.cc hud.cc infowidget.cc input.cc inventorylistview.cc inventory.cc joystick.cc key.cc \
- keyboard.cc map.cc notifications.cc playerview.cc soundext.cc targeticonbutton.cc \
- targets.cc trademenu.cc video.cc worldview.cc
+noinst_HEADERS = \
+ action.h \
+ buymenu.h \
+ chat.h \
+ client.h \
+ clientext.h \
+ entitymenu.h \
+ hud.h \
+ infowidget.h \
+ input.h \
+ inventory.h \
+ inventorylistview.h \
+ joystick.h \
+ key.h \
+ keyboard.h \
+ map.h \
+ notifications.h \
+ playerview.h \
+ soundext.h \
+ targeticonbutton.h \
+ targets.h \
+ testmodelview.h \
+ trademenu.h \
+ video.h \
+ worldview.h
+
+libclient_la_SOURCES = \
+ action.cc \
+ buymenu.cc \
+ chat.cc \
+ client.cc \
+ clientext.cc \
+ entitymenu.cc \
+ hud.cc \
+ infowidget.cc \
+ input.cc \
+ inventorylistview.cc \
+ inventory.cc \
+ joystick.cc \
+ key.cc \
+ keyboard.cc \
+ map.cc \
+ notifications.cc \
+ playerview.cc \
+ soundext.cc \
+ targeticonbutton.cc \
+ targets.cc \
+ testmodelview.cc \
+ trademenu.cc \
+ video.cc \
+ worldview.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
diff --git a/src/client/client.cc b/src/client/client.cc
index 318a0d4..ec2d002 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -102,8 +102,12 @@ void Client::init(int count, char **arguments)
// initialize user interface
ui::init();
- client_worldview = new WorldView(ui::root());
+ client_worldview = new WorldView(ui::root());
+
+ client_testmodelview = new TestModelView(ui::root());
+ client_testmodelview->hide();
+
// Initialize the video subsystem
if (!video::init()) {
quit(1);
@@ -139,20 +143,23 @@ void Client::init(int count, char **arguments)
func = core::Func::add("ui_console", func_ui_console);
func->set_info("toggle console");
- func = core::Func::add("ui_chat", Client::func_ui_chat);
+ func = core::Func::add("ui_chat", func_ui_chat);
func->set_info("toggle chat window");
- func = core::Func::add("ui_chatbar", Client::func_ui_chatbar);
+ func = core::Func::add("ui_chatbar", func_ui_chatbar);
func->set_info("toggle chat bar");
- func = core::Func::add("ui_inventory", Client::func_ui_inventory);
+ func = core::Func::add("ui_inventory", func_ui_inventory);
func->set_info("toggle inventory");
- func = core::Func::add("ui_map", Client::func_ui_map);
+ func = core::Func::add("ui_map", func_ui_map);
func->set_info("toggle map");
- func = core::Func::add("ui_menu", Client::func_ui_menu);
+ func = core::Func::add("ui_menu", func_ui_menu);
func->set_info("toggle main menu");
+
+ func = core::Func::add("testmodel", func_testmodel);
+ func->set_info("[str] load and view a single 3D model");
func = core::Func::add("menu", func_menu);
func->set_info("[command] menu functions");
@@ -239,6 +246,14 @@ void Client::frame(unsigned long timestamp)
} else if (core::game()->time() && !core::localcontrol()) {
ui::root()->show_menu("join");
}
+
+ if (testmodelview()->visible()) {
+ testmodelview()->raise();
+ }
+ if (ui::console()->visible()) {
+ ui::console()->raise();
+ ui::console()->set_focus();
+ }
} else {
if (core::localcontrol()) {
@@ -572,6 +587,26 @@ void Client::func_menu(std::string const &args)
}
}
+void Client::func_testmodel(std::string const &args)
+{
+ std::string modelname(args);
+ aux::trim(modelname);
+
+ if (!modelname.size()) {
+ con_print << "usage: testmodel [model name]" << std::endl;
+ }
+
+ //video::set_loader_message();
+ //video::frame_loader();
+
+ client()->client_testmodelview->set_modelname(modelname);
+ client()->client_testmodelview->raise(); // raise the window
+ client()->client_testmodelview->show();
-} // namespace client
+ if (ui::console()->visible()) {
+ ui::console()->raise();
+ ui::console()->set_focus();
+ }
+}
+} // namespace client
diff --git a/src/client/client.h b/src/client/client.h
index 288e9fa..a5ce297 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -12,6 +12,7 @@
#include "core/entity.h"
#include "client/clientext.h"
#include "client/soundext.h"
+#include "client/testmodelview.h"
#include "client/worldview.h"
#include "render/renderext.h"
@@ -66,6 +67,11 @@ public:
inline WorldView *worldview() {
return client_worldview;
}
+
+ /// model test widget
+ inline TestModelView *testmodelview() {
+ return client_testmodelview;
+ }
protected:
/// run a client frame
@@ -88,11 +94,14 @@ private:
static void func_ui_inventory(std::string const &args);
static void func_ui_map(std::string const &args);
static void func_ui_menu(std::string const &args);
+
+ static void func_testmodel(std::string const &args);
static void func_menu(std::string const &args);
static void func_view(std::string const &args);
WorldView *client_worldview;
+ TestModelView *client_testmodelview;
unsigned long previous_timestamp;
};
diff --git a/src/client/testmodelview.cc b/src/client/testmodelview.cc
new file mode 100644
index 0000000..31dc98f
--- /dev/null
+++ b/src/client/testmodelview.cc
@@ -0,0 +1,114 @@
+/*
+ client/testmodelview.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "ui/ui.h"
+#include "ui/paint.h"
+#include "client/testmodelview.h"
+#include "model/model.h"
+
+namespace client
+{
+
+TestModelView::TestModelView(ui::Widget *parent)
+{
+ set_background(true);
+ set_border(false);
+ set_label("testmodelview");
+ testmodelview_modelview = new ui::ModelView(this);
+ testmodelview_modelview->set_radius(1.0f);
+
+ testmodelview_text = new ui::PlainText(this);
+ testmodelview_text->set_label("text");
+ testmodelview_text->set_background(false);
+ testmodelview_text->set_border(false);
+
+ testmodelview_closebutton = new ui::Button(this);
+ testmodelview_closebutton->set_text("Close");
+ testmodelview_closebutton->set_background(true);
+}
+
+TestModelView::~TestModelView()
+{
+}
+
+void TestModelView::set_modelname(const std::string & modelname)
+{
+ model::Model *model = model::Model::load(modelname);
+ testmodelview_modelview->set_modelname(modelname);
+
+ std::ostringstream str;
+ str << modelname << '\n';
+
+ if (model) {
+ size_t frags = 0;
+
+ for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) {
+ frags += (*git)->size();
+ }
+ str << '\n';
+ str << "tris: " << model->model_tris_count << '\n';
+ str << "quads: " << model->model_quad_count << '\n';
+ str << "fragments: " << frags << '\n';
+ }
+ testmodelview_text->set_text(str.str());
+}
+
+void TestModelView::show()
+{
+ resize();
+ ui::Widget::show();
+}
+
+void TestModelView::hide() {
+ ui::Widget::hide();
+}
+
+void TestModelView::resize()
+{
+ // this view covers the entire screen
+ set_size(parent()->size());
+
+ // resize the label
+ testmodelview_text->set_size(width() - 16.0f, testmodelview_text->font()->height() * 5.0f);
+ testmodelview_text->set_location(8.0f, 8.0f);
+
+ // resize the 3d model view
+ testmodelview_modelview->set_size(width(),height());
+ testmodelview_modelview->set_location(0.0f, 0.0f);
+
+ // reposition close button
+ testmodelview_closebutton->set_size(
+ ui::UI::elementsize.width() * 1.5f,
+ ui::UI::elementsize.height()
+ );
+ testmodelview_closebutton->set_location(
+ width() - testmodelview_closebutton->width() - ui::UI::elementsize.height(),
+ height() - testmodelview_closebutton->height() - ui::UI::elementsize.height() * 0.5f
+ );
+}
+
+void TestModelView::draw_background()
+{
+ math::Color color(palette()->background());
+ color.a = 1.0f;
+ ui::Paint::set_color(color);
+ ui::Paint::draw_rectangle(global_location(), size());
+}
+
+bool TestModelView::on_emit(Widget *sender, const Event event, void *data)
+{
+ if (event == ui::Widget::EventButtonClicked) {
+ // slider value changed
+ if (sender == testmodelview_closebutton) {
+ hide();
+ }
+ return true;
+ }
+ return false;
+}
+
+} // namespace client
+
diff --git a/src/client/testmodelview.h b/src/client/testmodelview.h
new file mode 100644
index 0000000..6b38df6
--- /dev/null
+++ b/src/client/testmodelview.h
@@ -0,0 +1,52 @@
+/*
+ client/testmodelview.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_TESTMODELVIEW_H__
+#define __INCLUDED_CLIENT_TESTMODELVIEW_H__
+
+#include "ui/widget.h"
+#include "ui/button.h"
+#include "ui/plaintext.h"
+#include "ui/modelview.h"
+
+namespace client
+{
+
+/// the world view when connected
+class TestModelView : public ui::Widget
+{
+public:
+ TestModelView(ui::Widget *parent = 0);
+ virtual ~TestModelView();
+
+ void set_modelname(const std::string & modelname);
+
+ /// show the testmodelview
+ virtual void show();
+
+ /// hide the testmodelview
+ virtual void hide();
+
+protected:
+ /// resize te testmodelview
+ virtual void resize();
+
+ /// draw a black background
+ virtual void draw_background();
+
+ /// emit event handler
+ virtual bool on_emit(Widget *sender, const Event event, void *data);
+
+private:
+ ui::ModelView *testmodelview_modelview;
+ ui::Button *testmodelview_closebutton;
+ ui::PlainText *testmodelview_text;
+
+}; // class TestModelView
+
+} // namespace client
+
+#endif // __INCLUDED_CLIENT_TESTMODELVIEW_H__
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 3d7c452..851ad81 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -385,6 +385,7 @@ void Camera::frustum_default(float distance, float cx, float cy)
gl::rotate(-90.0f, 1.0f , 0.0f, 0.0f);
gl::translate(distance + 1.0f, 0.0f, 0.0f);
+ camera_eye.assign(-distance - 1.0f, 0.0f, 0.0f);
}
void Camera::ortho()
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 6e60f86..22ff90f 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -59,21 +59,8 @@ Globes globes_list;
/* ---- Prepare the renderer state --------------------------------- */
-void pass_prepare(float seconds)
+void pass_reset_lights()
{
- using namespace model;
-
- // render settings for this pass_prepare
- draw_lights = true;
- if (r_lights && (r_lights->value() <= 0.0f)) {
- draw_lights = false;
- }
-
- draw_particles = true;
- if (r_particles && (r_particles->value() <= 0.0f)) {
- draw_particles = false;
- }
-
// lighting settings for the default light GL_LIGHT0
GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat ambient_light[] = { r_ambient->value(), r_ambient->value(), r_ambient->value(), 1.0f };
@@ -94,6 +81,25 @@ void pass_prepare(float seconds)
// reset light state
gl::disable(GL_LIGHT1);
+}
+
+void pass_prepare(float seconds)
+{
+ using namespace model;
+
+ // render settings for this pass_prepare
+ draw_lights = true;
+ if (r_lights && (r_lights->value() <= 0.0f)) {
+ draw_lights = false;
+ }
+
+ draw_particles = true;
+ if (r_particles && (r_particles->value() <= 0.0f)) {
+ draw_particles = false;
+ }
+
+ // initialize lights
+ pass_reset_lights();
has_zone_light = false;
zone_color.assign(1.0);
@@ -1232,13 +1238,7 @@ void draw(float seconds)
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
- if (r_normalize && r_normalize->value()) {
- // enable full normalization
- gl::enable(GL_NORMALIZE);
- } else {
- // enable rescaling of normals
- gl::enable(GL_RESCALE_NORMAL);
- }
+ State::set_normalize(true);
gl::enable(GL_LIGHTING); // enable lighting
@@ -1250,13 +1250,7 @@ void draw(float seconds)
gl::disable(GL_LIGHTING); // disable lighting
- if (r_normalize && r_normalize->value()) {
- // disable full normalization
- gl::disable(GL_NORMALIZE);
- } else {
- // disable rescaling of normals
- gl::disable(GL_RESCALE_NORMAL);
- }
+ State::set_normalize(false);
gl::enable(GL_BLEND);
gl::depthmask(GL_FALSE); // disable depth buffer writing
diff --git a/src/render/draw.h b/src/render/draw.h
index 516da13..da5115f 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -15,6 +15,9 @@
namespace render
{
+/// reset lighting parameters
+void pass_reset_lights();
+
/// draw the world
void draw(float seconds);
diff --git a/src/render/state.cc b/src/render/state.cc
index 293e464..fb64319 100644
--- a/src/render/state.cc
+++ b/src/render/state.cc
@@ -152,4 +152,23 @@ void State::clear()
gl::disable(GL_TEXTURE_2D);
}
+void State::set_normalize(const bool enable)
+{
+ if (r_normalize && r_normalize->value()) {
+ // enable full normalization
+ if(enable) {
+ gl::enable(GL_NORMALIZE);
+ } else {
+ gl::disable(GL_NORMALIZE);
+ }
+ } else {
+ // enable rescaling of normals
+ if(enable) {
+ gl::enable(GL_RESCALE_NORMAL);
+ } else {
+ gl::disable(GL_RESCALE_NORMAL);
+ }
+ }
+}
+
} // namespace render
diff --git a/src/render/state.h b/src/render/state.h
index 3fa3b80..6387be8 100644
--- a/src/render/state.h
+++ b/src/render/state.h
@@ -40,6 +40,8 @@ public:
return render_vbo;
}
+ static void set_normalize(const bool enable=true);
+
private:
static int render_width;
static int render_height;
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 1485d79..e715119 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -8,6 +8,7 @@
#include "core/application.h"
#include "ui/modelview.h"
#include "ui/paint.h"
+#include "ui/ui.h"
#include "sys/sys.h"
#include "render/camera.h"
#include "render/draw.h"
@@ -53,6 +54,8 @@ void ModelView::set_modelname(const char *modelname)
modelview_axis.clear();
modelview_axis.change_direction(180);
modelview_axis.change_pitch(-15);
+ modelview_zoom = 1.0f;
+ modelview_radius = 0.75f;
}
void ModelView::set_color(const math::Color & color)
@@ -147,13 +150,25 @@ void ModelView::draw()
math ::Vector2f center(global_location() + size() * 0.5f);
gl::clear(GL_DEPTH_BUFFER_BIT);
+
+ const float minscreen(math::min(root()->width(),root()->height()));
+ const float minwidget(math::min(width(), height()));
+ const float reference_radius = radius() * minwidget / minscreen;
+ const float modelscale = reference_radius / model->radius();
// gl 3d mode
- render::Camera::frustum_default(modelview_zoom * model->radius(), center.x(), center.y());
+ render::Camera::frustum_default(modelview_zoom, center.x(), center.y());
+
+ // reset lighting
+ render::pass_reset_lights();
+ // enable lighting
+ gl::enable(GL_LIGHTING);
+
// apply manipulation
gl::push();
gl::multmatrix(modelview_axis);
+ gl::scale(modelscale, modelscale, modelscale);
gl::disable(GL_BLEND);
gl::depthmask(GL_TRUE); // enable writing to the depth buffer
@@ -162,15 +177,16 @@ void ModelView::draw()
gl::enable(GL_CULL_FACE); // enable culling
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
- // FIXME - initialize lights
- gl::enable(GL_LIGHTING);
-
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
+
+ render::State::set_normalize(true);
render::draw_model_fragments(model, core::localplayer()->color(), core::localplayer()->color_second(), core::application()->time(), true, true, 0.0f);
+
+ render::State::set_normalize(false);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
diff --git a/src/ui/modelview.h b/src/ui/modelview.h
index 7cbf76d..c235e99 100755
--- a/src/ui/modelview.h
+++ b/src/ui/modelview.h
@@ -26,6 +26,14 @@ public:
inline math::Color const &color() const {
return modelview_color;
}
+
+ inline float zoom() const {
+ return modelview_zoom;
+ }
+
+ inline float radius() const {
+ return modelview_radius;
+ }
void set_modelname(const char *modelname);
@@ -45,6 +53,10 @@ public:
* 1.0 is not zoomed out, 10.0 is zoomed out by a factor of 10
*/
void set_zoom(const float zoom);
+
+ inline void set_radius(const float radius) {
+ modelview_radius = radius;
+ }
protected:
/// draw the widget
@@ -71,6 +83,7 @@ private:
std::string modelview_modelname;
math::Color modelview_color;
float modelview_zoom;
+ float modelview_radius;
math::Axis modelview_axis;
math::Vector2f modelview_cursor;