Code: Select all
function Frustum(posx,posy,h,w)
if posx > w or posx < 0 or posy > h or posy < 0 then
return false
end
return true
end
Code: Select all
function Frustum(posx,posy,h,w)
if posx > w or posx < 0 or posy > h or posy < 0 then
return false
end
return true
end
Code: Select all
function CheckIfRectanglesIntersect( aX, aY, aWidth, aHeight, bX, bY, bWidth, bHeight )
--returns true if rectangles intersect
return (
( aX <= bX + bWidth ) and
( bX <= aX + aWidth ) and
( aY <= bY + bHeight ) and
( bY <= aY + aHeight )
)
end
I keep seeing people mention data structures like this but wouldn't even know where to begin to figure out how to implement it.T-Bone wrote:Also, instead of calculating for each object if it should be drawn or not, you can place all objects in a data stricture designed in such a way that you directly have access to the objects near the screen. That uses more memory but saves cpu power, which is in most cases worth it.
The surmise is that updating the data structure and then using it to cull will be faster than the otherwise O(n) loop.severedskullz wrote: I keep seeing people mention data structures like this but wouldn't even know where to begin to figure out how to implement it.
I am also suspicious regarding "saving cpu power" because wouldn't it be just as expensive to update the data structure than it is to use a linear algorithm to just loop through N items? You are already updating at N time in the update function, so I don't really see how any improvement can be done for drawing... The only thing I could see this as a use for is static entities and calls that don't ever update their position, but rather their position is determined by the position of the camera.
this, this, a thousand times this!spectralcanine wrote: And of course, as a general advice, don't bother with optimizations like this until you actually know you need them.
Users browsing this forum: Bing [Bot] and 9 guests