cocosnode user expectations - placement broken ?

1 view
Skip to first unread message

Claudio Canepa

unread,
Sep 9, 2009, 11:55:03 AM9/9/09
to cocos2d discuss
Use case broken:
In a scene composed by terrain + actors, scaling the actors changes
the rendered position
see the issue demo at
http://groups.google.com/group/cocos-discuss/web/cocos_placement_issue.py

Deep causes:

I think cocosnode breaks reasonable user expectations

base asumption: cocosnodes are the nodes in a scenograph, ie a
treelike scene description,
where childs gets placement ( position, rotation, scale ) relative to
his parent

Things that seems reasonable to expect:

1.
node.rotation = alpha + node.rotation
rotates the render of node by an angle alpha

2.
node.scale = 2*node.scale
duplicates the dimensions of the renderer node

3.
Because normally it will have some extension (ie not only a point),
the node must tell which point will be pined to the node.position
point.
In other worlds, a node have a bag of vertexes in node coordinates,
and it needs to transform
to the parent coord system. For that it must know which point in nodes
coords will map over
node.position when the render is done.
That points is usually known as node.anchor, and by definition the
point node.anchor will map
to node.position in parent coords.

*but* the current cocosnode don't behave like this.

The changes needed to comply are:

1. get rid of multiple anchors. There are expressing special cases
that can be expressed as
two chained proper cocosnodes.

2. CocosNode.transform() refactored as
def transform( self ):
glTranslatef( self.position[0] , self.position[1] , 0 )
glScalef( self.scale, self.scale, 1)
glRotatef( -self.rotation, 0, 0, 1)
glTranslatef( - self.anchor_x, - self.anchor_y, 0 )

( I omitted the camera case for clarity )

3. CocosNode.visit() is refactored so that .tranform() is called
before draw(), ie
def visit(self):
glPushMatrix()
self.transform()
# visit childs with z <0
...
# draw self
self.draw()
# visit childs with z>0
...
glPopMatrix

Questions, to the devs and any user in the list:

1. you thing my expectations are wrong ? If so, what will be the
correct ones ?
2. have you a strong case for multiple anchors ?

--
claudio
Reply all
Reply to author
Forward
0 new messages