[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] smooth surface rotate
Almost certainly *not* what you want, but here's a demo of doing this
under OpenGLContext by defining some geometry and then rotating its
parent transform. It's just using OpenGL's built-in ability to do the
transformation, so it tends to work fairly well.
I couldn't find *any* documentation on the Image object on the PyGame
documentation site. Which seems a little strange. There's docs for the
module, but not the Image objects themselves. I would imagine there's a
flag to say "don't expand" the image when rotating, but can't say for sure.
Anyway, good luck,
Mike
mike@zcentric.com wrote:
I want to take an image and rotate it around its center over and over
again in around 5 degree changes. pygame.transform.rotate() makes the
image grow. Is there anything i can do to not have the image grow (looks
like its moving across the screen)?
THanks
MIke
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
#! /usr/bin/env python
'''Simple demo of a rotating image mapped to a square
'''
from OpenGLContext import testingcontext
BaseContext, MainFunction = testingcontext.getInteractive()
from OpenGLContext.scenegraph.basenodes import *
from OpenGLContext.events.timer import Timer
from OpenGL.GL import *
from Numeric import array
scene = sceneGraph(
children = [
Transform(
DEF = "pivot",
children = [
Shape(
geometry = IndexedFaceSet(
coord = Coordinate(
point = [[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]],
),
coordIndex = [ 0,1,2,3 ],
texCoord = TextureCoordinate(
point = [[0,0],[1,0],[1,1],[0,1]],
),
texCoordIndex = [0,1,2,3 ],
),
appearance = Appearance(
texture = ImageTexture(
url = "nehe_glass.bmp",
),
),
)
],
),
PointLight(
location = (0,0,8),
),
],
)
class TestContext( BaseContext ):
rot = 6.283
initialPosition = (0,0,3)
def OnInit( self ):
self.sg = scene
self.trans = self.sg.children[0]
self.time = Timer( duration = 8.0, repeating = 1 )
self.time.addEventHandler( "fraction", self.OnTimerFraction )
self.time.register (self)
self.time.start ()
def getSceneGraph( self ):
"""Get the scene graph for the context (or None)"""
return self.sg
def OnTimerFraction( self, event ):
"""Modify the node"""
self.trans.rotation = 0,0,1,(self.rot*event.fraction())
if __name__ == "__main__":
MainFunction ( TestContext)