Using cam.Start3D to show a vector on a model

What I’m trying to achieve is to display a vector with an object (which could be a surface.DrawRect or perhaps a model of a cube or something similar) on a model in a DModelPanel. This vector is relative to the model in the panel.

The issue is that I’d like the object defining where the vector is to move with the model’s angles (when they get changed), and perhaps go behind the model. The angle-changing isn’t an issue, by the way.

Since the DModelPanel uses cam.Start3D to draw the model in it, I was thinking perhaps I could override the function it uses with some other code that would not only draw the model, but draw an object (possibly a 2D one like a surface.DrawRect as I said before) that moves with the model and goes behind it if it gets rotated too far instead of just getting drawn on top-
here’s a gif of what I’d really like to happen:

This is probably VERY hard to do (although I wouldn’t know because I have no idea how to use cam.Start3D), so any help or suggestions would be very helpful to me!
Thanks for reading this!

First, for 2D stuff(Like drawrect) in the 3D eviorment you should use ca.Start3D2D, 2nd the gif doesnt work ;n;

[del]Well, never mind about the gif, then.[/del] Fixed it!

I know I should use cam.Start3D2D for this, but the DModelPanel uses cam.Start3D only and I have no idea what to do if I wanted to change it. Would it be possible to put some code for a Start3D2D INSIDE a Start3D function?

If you use the draw function for the entity you won’t need to use cam.Start3D. Just use cam.Start3D2D(pos,ang,scale) where ang is an angle rotated around an axis to face the player

Ah, just looked that up, sounds like a good idea! I’ll test it later, thanks for that!

[editline]18th September 2015[/editline]

That’s strange- the ModelPanel.Entity:Draw() function doesn’t seem to get called whatsoever! Any alternatives? (I tried this just to check):

function ModelPanel.Entity:Draw()
print('Drawing entity...')

[editline]18th September 2015[/editline]

I think I’ll try overriding the ModelPanel:DrawModel function instead.

[editline]18th September 2015[/editline]

I think I need some help- what would I set the angles to if I wanted them to be local to the camera of the panel (would I just do (self.vLookatPos-self.vCamPos):Angle())? If so, how would I then rotate the shape being drawn so it always faces the camera?

I’m trying a lot of dodgy things to try and get a square to be shown at the centre of the model the DModelPanel is drawing-can someone tell me why this doesn’t seem to work?

render.SetScissorRect( leftx, topy, rightx, bottomy, true ) -- Not the issue

		local ang = self.aLookAngle
		if ( !ang ) then
			ang = (self.vLookatPos-self.vCamPos):Angle() -- The angle the camera is pointing at (I think)
		cam.Start3D2D( self.Entity:GetPos(), ang, 1 )

render.SetScissorRect( 0, 0, 0, 0, false )

I mean, ang is the camera angle, and self.Entity:GetPos() is obviously the model’s position, so why doesn’t this draw a red rect in the entity’s position relative to the camera? (perhaps I need to turn some sort of angle around?)

[editline]19th September 2015[/editline]

By the way, that code is a modified version of this.

Ah, the render library gets me the results I want rather than using cam.