CrowdModel crowd,model[,weight#]

Parameters

crowd - a crowd from CreateCrowd

model - an entity the crowd's people can be copies of

weight# (optional) - how often it is chosen, against the crowd's other models' weights; 1 (default)

Description

Adds a model to choose a crowd's people from.

A town of one kind of person looks like a factory. Give a crowd several models, such as a few characters, a dog and a child, and each person is a copy of one of them, chosen by weight: with a townsfolk model of weight 4 and a dog of weight 1, about one person in five is a dog. A model the crowd has already gets the new weight instead.

The models are chosen as people are made, so CrowdModel changes who comes next, not who is there: a crowd made with no model (CreateCrowd's model left out) fills up at once when its first model is added, and CrowdSize makes more. Every choice comes from the crowd's own random numbers, so the same crowd has the same people each time the program runs.

Hide the models, as you would for CopyEntity: the crowd shows its copies. A model that is the crowd itself, a weight of 0 or less, and an entity that isn't a crowd are runtime errors.

See also: CreateCrowd, CrowdSize, CrowdActivity, CopyEntity.

Example

; CrowdModel Example
; ------------------

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

camera=CreateCamera()
PositionEntity camera,0,12,-20
RotateEntity camera,30,0,0

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

; A 40 x 40 m park, one unit to a metre: the floor's top is at y=0
floor=CreateCube()
ScaleEntity floor,20,0.25,20
PositionEntity floor,0,-0.25,0
EntityColor floor,70,120,60

; Two models to make people from, hidden: the crowd shows its copies.
; A person 0.6 m across and 1.8 m tall, standing on y=0...
person=CreateCube()
ScaleMesh person,0.3,0.9,0.3
PositionMesh person,0,0.9,0
EntityColor person,60,90,200
HideEntity person

; ...and a dog
dog=CreateCube()
ScaleMesh dog,0.15,0.25,0.4
PositionMesh dog,0,0.25,0
EntityColor dog,160,110,60
HideEntity dog

; A crowd of 24 in a 10 m circle, made of both
crowd=CreateCrowd(0,0,0,0,10)
dog_weight#=1
CrowdModel crowd,person,4
CrowdModel crowd,dog,dog_weight
CrowdSize crowd,24

While Not KeyDown(1)

    ; + / - change how often a dog is chosen; the crowd is then made again
    new_weight#=dog_weight
    If KeyHit(13) And dog_weight<8 Then new_weight=dog_weight+1
    If KeyHit(12) And dog_weight>1 Then new_weight=dog_weight-1
    If new_weight<>dog_weight Then
        dog_weight=new_weight
        CrowdModel crowd,dog,dog_weight
        CrowdSize crowd,0
        CrowdSize crowd,24
    EndIf

    ; 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,True
    If KeyDown(205) Then TurnEntity camera,0,-1,0,True

    UpdateWorld
    RenderWorld

    Text 0,0,"Arrow keys: move camera   + / - : dog's weight   Esc: exit"
    Text 0,20,"CrowdModel crowd,person,4"
    Text 0,40,"CrowdModel crowd,dog,"+Int(dog_weight)

    Flip

Wend

End

Index