distance = objectA.getDistanceTo(objectB)
math module in python or similar languages should include a distance function of some kind. Just you will need to use the position of the object instead of the object itself. In UPBGE I can do this as well:
↩ Reply
import math distance = math.dist(objectA.position, objectB.position)
![Dani is standing among some trees [embedded image]](/pictures/danis_race_math/01.jpg)
drawDistance = 250 for object in scene.objects: if object.getDistanceTo(scene.active_camera) < drawDistance: Spawn(object) else: Despawn(object)
math.dist calls takes about 18 milliseconds. Which is not a lot. But for 60 FPS you want to have the whole thing ( all calculations of all logic and all rendering ) happen in under 16 milliseconds. So just calculating distances to all those objects, to either hide them or un-hide them takes way too much time. And I'm not even talking about the penalty of constantly hiding and un-hiding them. So there must be a better way.
↩ Reply
# Here I'm making a list of trees with their names. # Using lists in python. objects = [ ["Tree1", objectOfTree()], ["Tree2", objectOfTree()] ] # And here I want to find Tree2 Tree2 = None for object in objects: if object[0] == "Tree2": Tree2 = object[1] break
# Here I'm doing the same thing but with a dictionary. objects = { "Tree1":objectOfTree(), "Tree2":objectOfTree() } # And I'm getting Tree2 Tree2 = objcets.get("Tree2", None)
![Chunks of the map [embedded image]](/pictures/danis_race_math/02.jpg)
def Address(location, precision): ret = "" for axis in location[:2]: ret = ret + str(round(axis/precision))+":" return ret
1:1: or 20:-30: or <ul><li>15:0:, or something.
↩ Reply
chunks.get("1:1:", I get all of the objects who's address is 1:1:. Of course the objects needs to be placed in said dictionary beforehand. Luckily it could be done only once. And therefor it is done only once, on the first frame of the game.
↩ Reply
![Looking outside of the chunk [embedded image]](/pictures/danis_race_math/03.jpg)
![Sampling additional points [embedded image]](/pictures/danis_race_math/04.jpg)
import mathutils cam = scene.active_camera point = mathutils.Vector((0,0,-250)) point.rotate(cam.orientation.to_euler()) point += cam.position
mathutils.Vector() object can be rotated by a rotation object ( which if you are using euler is just a list of XYZ orientation changes in radians ). And also you can add any of them on the fly. So I can make a point which sits at 0 and 0 on X and Y and -250 on Z ( which is 250 in front of the camera if the camera was at the center of the 3D world and rotated to 0,0,0 ), I can then rotate that point to the rotation of the camera. Which will move the point in space to where this point would be if such rotation would be taken place. And then I can move it to where the camera is. And guess what. I will suddenly be in-front of the camera, 250 meters away.
↩ Reply
ret = [] points = [ mathutils.Vector((0,0,-1)), mathutils.Vector((0,0,0)), mathutils.Vector((0.5,0,-0.5)), mathutils.Vector((-0.5,0,-0.5)), mathutils.Vector((0,0,-2)) ] for point in points: point *= precision point.rotate(camera) point += location ret.append(Address(point, precision))
![Mini map [embedded image]](/pictures/danis_race_math/05.jpg)
![Dani is Grabbing [embedded image]](/pictures/danis_race_math/06.jpg)