added Engine::Object::setTextureScale() for box and plane texture scaling
git-svn-id: svn://anubis/anaglym/trunk@219 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
d3a161b0a7
commit
fd4b6b27c8
@ -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);
|
||||
|
5
Engine.h
5
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<float> > m_args;
|
||||
float m_color[4];
|
||||
GLuint m_texture;
|
||||
float m_texture_scale;
|
||||
};
|
||||
|
||||
class EngineFileLoader : public FileLoader
|
||||
|
14
ag.cc
14
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);
|
||||
|
1
ag.h
1
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);
|
||||
|
@ -695,6 +695,17 @@ This function sets the texture of <tt>obj</tt> to <tt>tex</tt>.
|
||||
<a href="#ag_loadTexture">ag.loadTexture()</a>.
|
||||
</p>
|
||||
|
||||
<a name="object_setTextureScale" />
|
||||
<h3>setTextureScale</h3>
|
||||
<p><tt>obj:setTextureScale(scale)</tt></p>
|
||||
<p>
|
||||
This function sets the "texture scale" for <tt>obj</tt>.
|
||||
Currently, texture scaling is only supported for boxes and planes.
|
||||
<tt>scale</tt> 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.
|
||||
</p>
|
||||
|
||||
<a name="object_setVisible" />
|
||||
<h3>setVisible</h3>
|
||||
<p><tt>obj:setVisible(visible_flag)</tt></p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user