How to adjust the position of an .OBJ model in processing(python)

220 views Asked by At

In processing, I loaded a model of a space ship by using the loadShape() and shape() command, but the model loaded is upside down.

When I use camera() command to try to solve the problem, a piece of the background is always get chopped and transformed then projected on the model.

So my question is, how can I turn the ship around, then adjust the perspective of the camera, without affecting the background?

1

There are 1 answers

0
George Profenza On

You should have a look at pushMatrix()/popMatrix(). Also checkout the 2D Transformations tutorial. It's using Java syntax and 2D(not Python and 3D), but it does a great job at explaining coordinate systems and using push/pop matrix calls.

Here is the LoadDisplayOBJ Python example modified so it draws the rocket on the right, without affecting the global coordinate system:

ry = 0


def setup():
    size(640, 360, P3D)
    global rocket
    rocket = loadShape("rocket.obj")


def draw():
    global ry
    background(0)
    lights()

    translate(width / 2, height / 2 + 100, -200)

    pushMatrix() #isolate coordinate system for rocket only (local)
    translate(200,0,0) #move the rocket to the right
    rotateZ(PI)
    rotateY(ry)
    shape(rocket)
    popMatrix()#exit rocked coordinate system, return to Processing's (global) coordinate system

    #if you draw something here, it will be at the centre, not the right

    ry += 0.02