Most of us have seen them: A 2d looking object that hovers over or near a 3d object in 3d space. It might be character names, health bars, or something else. In most cases, it always stays the same size on the screen, regardless of how far away the object is from the camera. I call them name plates.
I want them.
I figure I have two options to generate this effect.
Option one, which is conceptually simple, is just to create the name plate as a billboard and scale it to the size I want, with it 1 unit away from the camera. Then I just scale it relative to itself based on the distance between it and the camera using something like the following:
def distToZero(self, point3):
return( math.sqrt( math.pow(point3.getX(), 2) +
math.pow(point3.getY(), 2) +
math.pow(point3.getZ(), 2) ) )
def namePlateScaleTask(self, task):
self.namePlate.setScale( self.namePlate, self.distToZero( self.namePlate.getPos( base.camera ) )
return task.cont
Alternatively, I could make the name plate a child of render2d or aspect2d and find the correct location for it by projecting from the camera lens, like the following code I pulled from [url]render coord to aspect2d]:
def Update( renderNp, aspectNp ):
# Convert the point to the 3-d space of the camera
p3 = base.camera.getRelativePoint( render, renderNp.getPos() )
# Convert it through the lens to render2d coordinates
rp2 = Point2()
if base.camLens.project( p3, rp2 ):
ap2 = aspect2d.getRelativePoint( render2d, Point3(rp2[0], 0, rp2[1]) )
aspectNp.setPos( ap2.x, 0, ap2.z )
return Task.cont
My question is, which of these two methods puts the least amount of strain on the system, or are they about the same? I’m guessing the first option is less intensive, but I’d like confirmation.