From 11da99b3ad6405f0b78d0748959c6b4e76c8a016 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 17 Sep 2010 17:02:28 +0000 Subject: [PATCH] added ag::object::setTransparency() and Engine::Object::setTransparency() git-svn-id: svn://anubis/anaglym/trunk@316 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.h | 6 +++++- ag.cc | 16 ++++++++++++++++ ag.h | 1 + tests/checkerpick.lua | 3 ++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Engine.h b/Engine.h index 7556c1a..fef5ccb 100644 --- a/Engine.h +++ b/Engine.h @@ -68,7 +68,11 @@ class Engine m_color[0] = r; m_color[1] = g; m_color[2] = b; - m_color[3] = 1.0f; + render(); + } + void setTransparency(float t) + { + m_color[3] = 1.0f - t; render(); } void setTexture(GLuint tex); diff --git a/ag.cc b/ag.cc index 7207d49..6a74152 100644 --- a/ag.cc +++ b/ag.cc @@ -372,6 +372,8 @@ fail: lua_setfield(L, -2, "addTorqueRel"); lua_pushcfunction(L, object::setColor); lua_setfield(L, -2, "setColor"); + lua_pushcfunction(L, object::setTransparency); + lua_setfield(L, -2, "setTransparency"); lua_pushcfunction(L, object::setGravityMode); lua_setfield(L, -2, "setGravityMode"); lua_pushcfunction(L, object::setTexture); @@ -1443,6 +1445,20 @@ fail: return 0; } + int setTransparency(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 2 && lua_isnumber(L, 2)) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL) + { + obj->setTransparency(lua_tonumber(L, 2)); + } + } + return 0; + } + int setGravityMode(lua_State * L) { int argc = lua_gettop(L); diff --git a/ag.h b/ag.h index 0a08ec1..a735a86 100644 --- a/ag.h +++ b/ag.h @@ -89,6 +89,7 @@ namespace ag int setGravityMode(lua_State * L); int setTexture(lua_State * L); int setTextureScale(lua_State * L); + int setTransparency(lua_State * L); int getMass(lua_State * L); int setMass(lua_State * L); int getAABB(lua_State * L); diff --git a/tests/checkerpick.lua b/tests/checkerpick.lua index e94352d..927cc7d 100644 --- a/tests/checkerpick.lua +++ b/tests/checkerpick.lua @@ -3,9 +3,10 @@ function init_event() ground = ag.createBox(8, 8, 0.1, {static = true}) ground:setTexture(checker_texture) ag.setCamera(10, -10, 10, 0, 0, 0) - hilite = ag.createBox(2, 2, 0.1, {static = true}) + hilite = ag.createBox(2, 2, 0.1, {static = true, enable_blending = true}) hilite:setColor(0.3, 0.5, 1) hilite:setPosition(1, 1, 0.1) + hilite:setTransparency(0.4) ag.setCursorVisible(true) end