From fd4b6b27c8f85c4f823f3323f0afbf7372c765b5 Mon Sep 17 00:00:00 2001
From: Josh Holtrop
Date: Wed, 16 Dec 2009 02:43:15 +0000
Subject: [PATCH] added Engine::Object::setTextureScale() for box and plane
texture scaling
git-svn-id: svn://anubis/anaglym/trunk@219 99a6e188-d820-4881-8870-2d33a10e2619
---
Engine.cc | 9 ++++++---
Engine.h | 5 +++++
ag.cc | 14 ++++++++++++++
ag.h | 1 +
doc/index.html | 11 +++++++++++
5 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/Engine.cc b/Engine.cc
index 6ec8e89..452950c 100644
--- a/Engine.cc
+++ b/Engine.cc
@@ -1023,6 +1023,7 @@ Engine::Object::Object(bool is_static, OdeWorld & world,
for (int i = 0; i < 4; i++)
m_color[i] = 1.0f;
m_texture = 0;
+ m_texture_scale = 1.0f;
createManagedObject();
}
@@ -1045,6 +1046,7 @@ Engine::Object::Object(const Engine::Object & orig)
for (int i = 0; i < 4; i++)
m_color[i] = orig.m_color[i];
m_texture = orig.m_texture;
+ m_texture_scale = orig.m_texture_scale;
if (m_is_managed)
render();
}
@@ -1182,7 +1184,8 @@ void Engine::Object::render()
{
if (m_texture != 0)
{
- glTexCoord2fv(tex_coords[v]);
+ glTexCoord2f(tex_coords[v][0] * m_texture_scale,
+ tex_coords[v][1] * m_texture_scale);
}
glVertex3f(sides[s].verts[v][0] * width / 2.0,
sides[s].verts[v][1] * depth / 2.0,
@@ -1269,12 +1272,12 @@ void Engine::Object::render()
float half_span = num_sections * section_size / 2.0;
float x_c = x * section_size - half_span;
float y_c = y * section_size - half_span;
- glTexCoord2f(0.0, y);
+ glTexCoord2f(0.0, y * m_texture_scale);
glVertex3f(x_o + rotated_x[0] * x_c + rotated_y[0] * y_c,
y_o + rotated_x[1] * x_c + rotated_y[1] * y_c,
z_o + rotated_x[2] * x_c + rotated_y[2] * y_c);
x_c += section_size;
- glTexCoord2f(1.0, y);
+ glTexCoord2f(1.0, y * m_texture_scale);
glVertex3f(x_o + rotated_x[0] * x_c + rotated_y[0] * y_c,
y_o + rotated_x[1] * x_c + rotated_y[1] * y_c,
z_o + rotated_x[2] * x_c + rotated_y[2] * y_c);
diff --git a/Engine.h b/Engine.h
index 02f98ef..c7cf793 100644
--- a/Engine.h
+++ b/Engine.h
@@ -68,6 +68,10 @@ class Engine
render();
}
void setTexture(GLuint tex);
+ void setTextureScale(float scale)
+ {
+ m_texture_scale = scale;
+ }
void draw();
dReal getMass() { return m_ode_object->getMass(); }
void setMass(dReal mass) { m_ode_object->setMass(mass); }
@@ -93,6 +97,7 @@ class Engine
refptr< std::vector > m_args;
float m_color[4];
GLuint m_texture;
+ float m_texture_scale;
};
class EngineFileLoader : public FileLoader
diff --git a/ag.cc b/ag.cc
index 546f3da..adbeb43 100644
--- a/ag.cc
+++ b/ag.cc
@@ -1054,6 +1054,20 @@ namespace ag
return 0;
}
+ int setTextureScale(lua_State * L)
+ {
+ int argc = lua_gettop(L);
+ if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2))
+ {
+ Engine::Object * obj = getObject(L, 1);
+ if (obj != NULL)
+ {
+ obj->setTextureScale(lua_tonumber(L, 2));
+ }
+ }
+ return 0;
+ }
+
int getMass(lua_State * L)
{
int argc = lua_gettop(L);
diff --git a/ag.h b/ag.h
index f17197c..01cac42 100644
--- a/ag.h
+++ b/ag.h
@@ -74,6 +74,7 @@ namespace ag
int addTorqueRel(lua_State * L);
int setColor(lua_State * L);
int setTexture(lua_State * L);
+ int setTextureScale(lua_State * L);
int getMass(lua_State * L);
int setMass(lua_State * L);
int getAABB(lua_State * L);
diff --git a/doc/index.html b/doc/index.html
index f21d904..9098f46 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -695,6 +695,17 @@ This function sets the texture of obj to tex.
ag.loadTexture().
+
+setTextureScale
+obj:setTextureScale(scale)
+
+This function sets the "texture scale" for obj.
+Currently, texture scaling is only supported for boxes and planes.
+scale actually scales the texture coordinates.
+Hence a scale of 4 would appear to shrink the texture by a factor of
+4 and tile the texture 16 times where it normally would have once.
+
+
setVisible
obj:setVisible(visible_flag)