AddProfileRect profile,x#,y#,width#,height#[,corner_radius#]

Parameters

profile - profile handle

x# - x coordinate of the centre of the rectangle
y# - y coordinate of the centre of the rectangle

width# - width, greater than 0

height# - height, greater than 0

corner_radius# (optional) - radius that rounds the corners; 0 for square corners (default)

Description

Adds a separate closed rectangle, with optional rounded corners, to a profile.

Each call adds its own closed outline, centred on x#,y#. A rectangle inside another closed outline becomes a hole, so two rectangles make a window frame, a picture frame or a hollow beam, and a rectangle inside a house's plan can be a courtyard.

Square corners stay crisp and rounded corners are shaded smoothly. A corner radius larger than half the shorter side is reduced to fit, so a very large radius gives a shape with fully rounded ends. When you frame a rounded rectangle, give the inner one a radius smaller by the width of the frame, as the example does, so the frame is the same width all the way round.

Each edge builds the surface set by ProfileSurface. A width or height that is not greater than 0, or a negative corner radius, stops the program with a runtime error. A profile handle that does not exist, or a coordinate or size that is not a finite number, stops the program with a runtime error.

See also: AddProfileCircle, AddProfilePoint, CreateProfile, CreateExtrusion.

Example

; AddProfileRect Example
; ----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-4

light=CreateLight()
RotateEntity light,45,45,0

; A stand that turns the window frame from side to side
stand=CreatePivot()
PositionEntity stand,0,1,0

radius_steps=0
frame_steps=2
frame_mesh=0

While Not KeyDown(1)

    ; [ / ] round the corners, - / + change the width of the frame
    If KeyHit(26) And radius_steps>0 Then
        radius_steps=radius_steps-1
        If frame_mesh Then FreeEntity frame_mesh
        frame_mesh=0
    EndIf
    If KeyHit(27) And radius_steps<5 Then
        radius_steps=radius_steps+1
        If frame_mesh Then FreeEntity frame_mesh
        frame_mesh=0
    EndIf
    If KeyHit(12) And frame_steps>1 Then
        frame_steps=frame_steps-1
        If frame_mesh Then FreeEntity frame_mesh
        frame_mesh=0
    EndIf
    If KeyHit(13) And frame_steps<5 Then
        frame_steps=frame_steps+1
        If frame_mesh Then FreeEntity frame_mesh
        frame_mesh=0
    EndIf

    If frame_mesh=0 Then
        corner#=radius_steps*0.1
        border#=frame_steps*0.05
        ; The outside edge: 1.2 m wide, 1.6 m tall, centred on 0,0
        outline=CreateProfile()
        AddProfileRect outline,0,0,1.2,1.6,corner
        ; A smaller rectangle inside it becomes the opening
        inner_corner#=corner-border
        If inner_corner<0 Then inner_corner=0
        AddProfileRect outline,0,0,1.2-border*2,1.6-border*2,inner_corner
        ; Push it back 10 cm
        frame_mesh=CreateExtrusion(outline,0.1,False,stand)
        FreeProfile outline
        EntityColor frame_mesh,240,240,235
    EndIf

    RotateEntity stand,0,Sin(MilliSecs()*0.05)*35,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   [ / ] : corner radius   - / + : frame width   Esc: exit"
    Text 0,20,"AddProfileRect outline,0,0,1.2,1.6,"+corner
    Text 0,40,"AddProfileRect outline,0,0,"+(1.2-border*2)+","+(1.6-border*2)+","+inner_corner

    Flip

Wend

End

Index