From: Matthias <Sta...@gm...> - 2005-11-07 22:24:37
|
Hi! I am very new to ODE! I had a look at tutorial 1 and 2, and i wanted to make my own little test sample! The program is very similar to tutorial2 but very selfmade, but it doesnt work! Why? I dont know!! I think there is a problem with the coordinates! I wrote the following code: #! /usr/bin/env python import pygame from pygame.locals import * import ode WIDTH = 800 HEIGHT = 600 def coord(x, y): x = x * (WIDTH / 4); y = HEIGHT - y * (HEIGHT / 4); return x, y def initPygame(): pygame.init() srf = pygame.display.set_mode( (WIDTH, HEIGHT) ) pygame.display.set_caption('Kran Beispiel mittels ODE') return srf def initOde(): world = ode.World() world.setGravity( (0, -9.81, 0) ) return world def makeKugel(w): kugel = ode.Body(w) m = ode.Mass() m.setBox(7900, 0.2, 0.2, 0.3) kugel.setMass(m) kugel.setPosition( (3, 3.8, 0) ) return kugel def drawKran(srf): srf.lock() pygame.draw.rect(srf, (100, 200, 40), (coord(0, 4), coord(2, 3.8)), 0) pygame.draw.rect(srf, (100, 200, 40), (coord(0, 4), coord(0.2, 0)), 0) srf.unlock() if __name__ == '__main__': loop = True fps = 50 dt = 1.0 / fps clk = pygame.time.Clock() srf = initPygame() world = initOde() kugel = makeKugel(world) bj = ode.BallJoint(world) bj.setAnchor( (2, 3.8, 0) ) bj.attach(kugel, ode.environment) while (loop): for e in pygame.event.get(): if (e.type == QUIT): loop = False srf.fill( (255,255,255) ) drawKran(srf) kx, ky, kz = kugel.getPosition() print kx, ky, kz pygame.draw.line(srf, (0,0,0), coord(2, 3.8), coord(kx, ky), 3) pygame.draw.rect(srf, (0,100,50), (coord(kx, ky), coord(kx + 0.1, ky - 0.1)), 0) pygame.display.flip() world.step(dt) clk.tick(fps) if you find the bugs please talk to me like talking to a four year old child (maybe some explanation would be nice ;) )! thanks, Matthias -- Highspeed-Freiheit. Bei GMX supergünstig, z.B. GMX DSL_Cityflat, DSL-Flatrate für nur 4,99 Euro/Monat* http://www.gmx.net/de/go/dsl |