How to create an rectangle in a 3d area via vector&angle

335 Views Asked by At

I have a 3d game where I will create an rectangle which is working as screen and the game itself works with vectors to positions. so I will create an rectangle and have only these parameters aviable:

start position ->vector (x,y,z). Angle(rotation) of object(x,y,z). size of rectangle.

now also the object need to be roatet to the right side so they are using angels also (x,y,z).

example:

position:-381.968750 -28.653845 -12702.185547
angle: -0.000 90.000 90.000

What I will create is an little bit hard but as idea simple.

I choose 2 complete different positions and angles and will create from the first vector to the second an rectangle.

I can only create an rectangle with the start point and angle. and I can set the size so (x,y)

So I will now insert 2 positions(vectors) with 2 different angles

The rectangle will have the middle value between the first and second angle so like (90 and 0) -> 45

And the rectangle will start at the start vector and will end with his own size so I don't have a chance to use the end vector directly.

Legendary on photo:

Green=>start and end positions(vectors).

red => the marked zone.

Blue => how I will have the rectangle.

enter image description here

    aem_point = vgui.Create( "AEM.Main.Panel" )
if IsValid(aem_point) then
    aem_point:SetSize( 2,2 ) -- <-the size that i can set   
    aem_point:SetPos( 0, 0 )
    aem_ph = vgui.Create( "DHTML", aem_point )  
    aem_ph:SetSize( aem_point:GetSize() )
    aem_ph:SetPos(aem_point:GetPos())
    aem_ph:SetVisible( true )
    aem_ph:SetHTML([[
        <html>
        <body style="margin:0px;padding:0px;font-size:20px;color:red;border-style: solid;border-color: #ff0000;background-color:rgba(255,0,0,0.1);">

        </body>
        </html>
    ]] ) 
end

    hook.Add( "PostDrawOpaqueRenderables", "DrawSample3D2DFrame" .. math.random(), function()
        if first and dat_finish then
vgui.Start3D2D( input_position, input_angle, 1 ) -- <-and position&vec
            aem_point:Paint3D2D()
            vgui.End3D2D()
        end
    end )   
1

There are 1 best solutions below

0
On

Oh so you want to create a 3d2d plane from 2 vector positions?

    Vec1 = A
    Vec2 = B
    input_position = ( Vec1 + Vec2 ) / 2

A problem you will run into is you need 3 points to generate a plane, so while you can get the position of the screen to get the angle of it you will need another point.

If these screens of yours are staticly set, as in you put their position into the lua code manually and dont intend to have it move or anything, just manually putting in the angle is by far the most simple approch.

upright

slanted

both

As you can see, both of these planes are on the same two points, but they have diffrent angles.

I wrote the demo in expression 2, this should make it clear as to how this works, if you have any other questions just ask.

    A = entity(73):pos()
    B = entity(83):pos()

    if(first())
    {
        holoCreate(1)
        holoCreate(2)
    }
    holoPos(1,(A+B)/2)

    holoScaleUnits(1,vec( abs(B:y() - A:y()) ,  1  ,  abs(sqrt(  ( B:z() - A:z() ) ^ 2  +  ( B:x() - A:x() ) ^ 2  ))))
    holoAng(1,ang(0,90,45))

    holoPos(2,(A+B)/2)

    holoScaleUnits(2,vec( abs(sqrt(  ( B:x() - A:x() ) ^ 2  +  ( B:y() - A:y() ) ^ 2  )) ,  1  , abs(B:z()-A:z())))
    holoAng(2,ang(0,45,0))