 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
jimjamjahaa
Joined: 03 Oct 2005 Posts: 17
|
Posted: Wed Oct 12, 2005 2:17 am Post subject: please help me debug my code |
|
|
i am trying to implement some clipping in to my game
here are the 2 functions used for this
| Code: |
function compOutCode(x, y)
local outcode = 0
if y <0 then
outcode = bottom
end
if y > 272 then
outcode = top
end
if x < 0 then
outcode = outcode + left
end
if x > 480 then
outcode = outcode + right
end
return outcode
end
function drawLineClipped(x0,y0,x1,y1,col)
local accept, done = false
local out1, out2, outout, _x, _y = 0
out1 = compOutCode(x0, y0)
out2 = compOutCode(x1, y1)
repeat
if (out1 == inside and out2 == indide) then
accept = true
done = true
break
elseif not out1 * out2 == inside then -- <<<HERE!
done = true
break
end
if out1 == inside then
outout = out2
else
outout = out1
end
-- if top in outout
if outout == 2 or outout == 10 or outout == 11 then
_x = x0 + (x1 - x0) * (272 - y0) / (y1 - y0)
_y = ymax
end
-- if bottom
if outout == 4 or outout == 12 or outout == 13 then
_x = x0 + (x1 - x0) * (-y0) / (y1 - y0);
_y = 272
-- else if right
elseif outout == 9 or outout == 13 or outout == 11 then
_y = y0 + (y1 - y0) * (480 - x0) / (x1 - x0);
_x = 480
-- else if left
elseif outout == 8 or outout == 12 or outout == 14 then
_y = y0 + (y1 - y0) * (-x0) / (x1 - x0);
_x = 0
end
if outout == out1 then
x0 = _x
y0 = _y
out1 = compOutCode(x0,y0)
else
x1 = _x
y1 = _y
out2 = compOutCode(x1,y1)
end
until done == true
if accept == true then
screen:drawLine(x0,y0,x1,y1,col)
end
end
|
i get an error at the place marked "-- <<<HERE!" complaining about doing arithmatic on a boolean variable. i mean, sure its declared as 0, but i dont mean for it to be boolean. the function compOutCode(x,y) will be returning 0 too in this scenario i am using it in.
so umm... help? please say if you dont get what im saying here. |
|
| Back to top |
|
 |
arrggg
Joined: 29 Sep 2005 Posts: 11
|
Posted: Wed Oct 12, 2005 4:15 am Post subject: |
|
|
| is "bottom" and "top" defined? |
|
| Back to top |
|
 |
jimjamjahaa
Joined: 03 Oct 2005 Posts: 17
|
Posted: Wed Oct 12, 2005 4:20 am Post subject: |
|
|
| Code: |
-- globals
red = Color.new(255, 0, 0);
black = Color.new(0, 0, 0);
white = Color.new(255, 255, 255);
green = Color.new(0, 255, 0);
pi = 3.141592653589
rm_menu = 0
rm_game = 1
room = rm_game
inside = 0
top = 2
bottom = 4
left = 8
right = 9
|
is the first bit of code in the script :)
edit: its odd, when i get rid of the offending code, it complains about something in the function compOutCode(), but to get to where it has the original error, it must already have executed compOutCode twice.... strange.
i get the feeling it might be doing quite a few passes without an error, and then erroring at the end for some unforseen reason. i dont know. i need to know how to debug really, thus my other thread i posted .... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|