added local PMF rendering

This commit is contained in:
Ben Russell (300178622) 2012-11-07 14:34:23 +13:00
parent 8cf8f4545d
commit 94d93023d0
5 changed files with 75 additions and 64 deletions

View File

@ -170,7 +170,7 @@ void net_deinit(void);
void render_vxl_redraw(camera_t *camera, map_t *map);
void render_cubemap(uint32_t *pixels, int width, int height, int pitch, camera_t *camera, map_t *map);
void render_pmf_bone(uint32_t *pixels, int width, int height, int pitch, camera_t *cam_base,
model_bone_t *bone,
model_bone_t *bone, int islocal,
float px, float py, float pz, float ry, float rx, float scale);
int render_init(int width, int height);
void render_deinit(void);

View File

@ -82,7 +82,17 @@ table = common.get_map_pillar(px, pz) @
this will be nil if there is no map loaded
note, the data wraps around here!
note, the data wraps around here (wrt px,pz)!
common.set_map_pillar(px, pz, table)
sets a full pillar of data
this will be nil if there is no map loaded
the data is checked before setting,
and will throw a lua error if it fails.
note, the data wraps around here (wrt px,pz)!
client.camera_point(dx, dy, dz, zoom = 1.0, roll = 0.0) @
points the camera in a direction with zoom factor "zoom"
@ -180,7 +190,7 @@ client.model_render_bone_global(pmf, boneidx, px, py, pz, ry, rx, scale) @
then around X by "rx" radians,
and scaled "scale" times
client.model_render_bone_local(pmf, boneidx, px, py, pz, ry, rx, scale)
client.model_render_bone_local(pmf, boneidx, px, py, pz, ry, rx, scale) @
renders a bone at camera-local position (px,py,pz),
rotated around Y by "ry" radians,

35
lua.c
View File

@ -459,7 +459,6 @@ int icelua_fn_client_camera_get_forward(lua_State *L)
return 3;
}
// client.model_render_bone_global(pmf, boneidx, px, py, pz, ry, rx, scale)
int icelua_fn_client_model_render_bone_global(lua_State *L)
{
int top = icelua_assert_stack(L, 8, 8);
@ -486,7 +485,38 @@ int icelua_fn_client_model_render_bone_global(lua_State *L)
scale = lua_tonumber(L, 8);
render_pmf_bone(screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam,
bone, px, py, pz, ry, rx, scale);
bone, 0, px, py, pz, ry, rx, scale);
return 0;
}
int icelua_fn_client_model_render_bone_local(lua_State *L)
{
int top = icelua_assert_stack(L, 8, 8);
float px, py, pz;
float rx, ry;
float scale;
model_t *pmf = lua_touserdata(L, 1);
if(pmf == NULL)
return luaL_error(L, "not a model");
int boneidx = lua_tointeger(L, 2);
if(boneidx < 0 || boneidx >= pmf->bonelen)
return luaL_error(L, "bone index %d out of range, len is %d", boneidx, pmf->bonelen);
model_bone_t *bone = pmf->bones[boneidx];
px = lua_tonumber(L, 3);
py = lua_tonumber(L, 4);
pz = lua_tonumber(L, 5);
ry = lua_tonumber(L, 6);
rx = lua_tonumber(L, 7);
scale = lua_tonumber(L, 8);
render_pmf_bone(screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam,
bone, 1, px, py, pz, ry, rx, scale);
return 0;
}
@ -518,6 +548,7 @@ struct icelua_entry icelua_common[] = {
{icelua_fn_common_model_bone_set, "model_bone_set"},
{icelua_fn_common_model_bone_find, "model_bone_find"},
{icelua_fn_client_model_render_bone_global, "model_render_bone_global"},
{icelua_fn_client_model_render_bone_local, "model_render_bone_local"},
{NULL, NULL}
};

View File

@ -38,6 +38,7 @@ BTSK_LOOKRIGHT = SDLK_RIGHT
zoom = 1.0
angx = 0.0
angy = 0.0
rotpos = 0.0
key_left = false
key_right = false
@ -54,7 +55,6 @@ key_space = false
-- create a test model
mdl_test = client.model_new(1)
print(client.model_len(mdl_test))
--[[
mdl_test_bone_data = {
{radius=192, x= 0 ,y= 0 ,z= 0 , r=255,g=170,b=0 },
{radius=96 , x= 256,y= 0 ,z= 0 , r=255,g=0 ,b=0 },
@ -64,41 +64,8 @@ mdl_test_bone_data = {
{radius=96 , x= 0 ,y=-256,z= 0 , r=255,g=0 ,b=255},
{radius=96 , x= 0 ,y= 0 ,z=-256, r=255,g=255,b=0 },
}
]]
mdl_test_bone_data = {}
mdl_test, mdl_test_bone = client.model_bone_new(mdl_test)
function setzapper()
local i
mdl_test_bone_data[1] = {radius=100, x=0,y=0,z=0, r=96,g=255,b=48}
for i=2,4000 do
local t = math.floor(math.random()*(i-2))+1
t = i-1
local rd = mdl_test_bone_data[t].radius
mdl_test_bone_data[i] = {
radius=math.floor(math.random()*50+50),
x=mdl_test_bone_data[t].x+math.floor((math.random()*2-1)*rd),
y=mdl_test_bone_data[t].y+math.floor((math.random()*2-1)*rd),
z=mdl_test_bone_data[t].z+math.floor((math.random()*2-1)*rd),
r=96,g=255,b=48,
}
math.random()
end
end
print(mdl_test, mdl_test_bone)
setzapper()
client.model_bone_set(mdl_test, mdl_test_bone, "test", mdl_test_bone_data)
do
local boneidx
boneidx = client.model_bone_find(mdl_test, "test")
print(boneidx)
boneidx = client.model_bone_find(mdl_test, "boner")
print(boneidx)
boneidx = client.model_bone_find(mdl_test, "abcdefghijklmnopqrstuvwxyz")
print(boneidx)
boneidx = client.model_bone_find(mdl_test, "")
print(boneidx)
end
--TODO!
--[[
client.model_bone_free(mdl_test, mdl_test_bone)
client.model_free(mdl_test)
@ -180,14 +147,7 @@ function h_tick_camfly(sec_current, sec_delta)
client.camera_move_to(nx, ny, nz)
end
--setzapper()
local i
for i=1,#mdl_test_bone_data do
mdl_test_bone_data[i].radius = 100+50*math.sin((sec_current*1000+i)*math.pi*2/500)
end
client.model_bone_set(mdl_test, mdl_test_bone, "test", mdl_test_bone_data)
rotpos = rotpos + sec_delta*120.0
-- wait a bit
return 0.01
@ -240,16 +200,13 @@ function client.hook_key(key, state)
end
end
rotpos1 = 0
rotpos2 = 0
rotpos3 = 0
function client.hook_render()
client.model_render_bone_global(mdl_test, mdl_test_bone,
120.5, 50.5, 150.5,
rotpos1, rotpos2, 1.0+0.5*math.sin(rotpos3))
rotpos1 = rotpos1 + 0.01
rotpos2 = rotpos2 + 0.004
rotpos3 = rotpos3 + 0.071
rotpos*0.01, rotpos*0.004, 1.0+0.5*math.sin(rotpos*0.071))
client.model_render_bone_local(mdl_test, mdl_test_bone,
1-0.2, 600/800-0.2, 1.0,
rotpos*0.01, rotpos*0.004, 0.1)
end
print("pkg/base/main_client.lua loaded.")

View File

@ -832,7 +832,7 @@ void render_pmf_box(float x, float y, float z, float depth, float r, uint32_t co
}
void render_pmf_bone(uint32_t *pixels, int width, int height, int pitch, camera_t *cam_base,
model_bone_t *bone,
model_bone_t *bone, int islocal,
float px, float py, float pz, float ry, float rx, float scale)
{
// stash stuff in globals to prevent spamming the stack too much
@ -877,9 +877,16 @@ void render_pmf_bone(uint32_t *pixels, int width, int height, int pitch, camera_
z *= scale;
// offsettate
x += (px - cam_base->mpx);
y += (py - cam_base->mpy);
z += (pz - cam_base->mpz);
x += px;
y += py;
z += pz;
if(!islocal)
{
x -= cam_base->mpx;
y -= cam_base->mpy;
z -= cam_base->mpz;
}
// get correct centre depth
float max_axis = fabsf(x);
@ -891,14 +898,20 @@ void render_pmf_bone(uint32_t *pixels, int width, int height, int pitch, camera_
float depth = max_axis/dlen;
// cameranananinate
if(!islocal)
{
float nx = x*cam_base->mxx+y*cam_base->mxy+z*cam_base->mxz;
float ny = x*cam_base->myx+y*cam_base->myy+z*cam_base->myz;
float nz = x*cam_base->mzx+y*cam_base->mzy+z*cam_base->mzz;
depth *= nz;
x = nx;
y = ny;
z = nz;
}
depth *= z;
// plotinate
render_pmf_box(-nx, ny, nz, depth, pt->radius*scale, color);
render_pmf_box(-x, y, z, depth, pt->radius*scale, color);
}
}