The Quad Property

The sprite.quad property is a list of four points that specify the screen coordinates of the corners of a sprite. If the quad property is set in Lingo, Director will distort the sprite accordingly. This allows the rendering of 3D rotation of a sprite.

Drag on the screen to spin the object
Quad propertysource movie

property sp
property verts
property trans
property rotVelo

on beginsprite(me)
sp = sprite(me.spritenum)
verts = []
verts[1] = vector(-1,1,0)
verts[2] = vector(1,1,0)
verts[3] = vector(1,-1,0)
verts[4] = vector(-1,-1,0)
trans = transform()
trans.scale = vector(150,150,1)
rotVelo = vector(.3,.2,0)

on exitframe()

on modelFrame()

on render()
eyez = 500
ptList = []
repeat with v = 1 to 4
vec = trans * verts[v]
persp = eyez / (vec.z + eyez)
pt = point(vec.x * persp, vec.y * persp) + stageCenter
end repeat
sp.quad = ptList

The Model
The animation model in this demo consists of four vectors, a transform, and a rotational velocity. The four vectors specify the corners of the object, and are analogous to a “model resource”. The transform is used to specify the scale, translation, and rotation of the object. Each model frame, the transform is rotated by a vector that specifies rotational velocity.

The model could have been stored in four vectors that specify 3D world coordinates, without using a transform. But keeping the resource information and transform separate makes transforming easier, and makes it easier to animate the corners with respect to each other.

•How would you change the “registration point” of the plane?

Multiplying each resource vector by the transform gives the 3D world coordinates of the corners. The perspective equation is then used to map the 3D points to 2D. The 2D points are put in a list which is used to set the sprite’s quad property. The order of the points is clockwise from upper-left for right side up facing the viewer, which is the reason for the order of the resource vectors.

The next section shows how to combine quads to make 3D objects.

One thought on “The Quad Property

  1. Craig Busing

    I found your blog’s link posted by a friend on Facebook. Thanks for putting useful information on the world wide web. It’s hard to find these things these days.

Leave a Reply

Your email address will not be published. Required fields are marked *