newsb

01-02-2013, 06:25 AM

What seems to be the problem with this rotation here (python-code) ?

I'm drawing an arrow from (x1,y1,z2) to (x2,y2,z2). Please see this and I hope you can explain what is going on...

def coordSysArrow(x1, y1, z1, x2, y2, z2):

glPushMatrix()

glPushAttrib( GL_POLYGON_BIT ) # includes GL_CULL_FACE

glDisable(GL_CULL_FACE) # draw from all sides

# Size of cone in arrow:

coneFractionAxially = 0.2

coneFractionRadially = 0.1

# Calculate cone parameters:

v = numpy.array((x2-x1, y2-y1, z2-z1))

norm_of_v = numpy.sqrt( numpy.dot(v,v) )

coneHgt = coneFractionAxially * norm_of_v

coneRadius = coneFractionRadially * norm_of_v

vConeLocation = (1.0-coneFractionAxially) * v

# Construct transformation matrix

mat44 = numpy.eye(4)

normalized_v = v/norm_of_v

mat44[0,0] = normalized_v[0]

mat44[1,1] = normalized_v[1]

mat44[2,2] = normalized_v[2]

# -----------------------

# Draw line + cone

# -----------------------

# Draw single line:

glBegin(GL_LINES)

glVertex3f(x1, y1, z1) # from

glVertex3f(x2, y2, z2) # to

glEnd() # GL_LINES

# Move and rotate in position:

glTranslate( *vConeLocation )

if 0: # turn on/off here

#glLoadIdentity()

glMultMatrixf( mat44 ) # <===== PROBLEM HERE?!?! WHAT?

# Make a cone!

cone_obj = gluNewQuadric();

# gluCylinder(gluNewQuadr, Radius_base, Radius_top,

# height, slices, stacks)

gluCylinder(cone_obj, 0, coneRadius,\

coneHgt, 8, 1);

glPopAttrib() # GL_CULL_FACE

glPopMatrix()

As you can see I've made an option to disable using the mat44-matrix. When I disable it, the cone gets drawn but the rotation is wrong. When I enable it, the cone is NOT drawn... Am I multiplying with a wrong rotation matrix and does that explain why nothing gets drawn?

There are no errors/warnings or anything... I don't understand this...

I'm drawing an arrow from (x1,y1,z2) to (x2,y2,z2). Please see this and I hope you can explain what is going on...

def coordSysArrow(x1, y1, z1, x2, y2, z2):

glPushMatrix()

glPushAttrib( GL_POLYGON_BIT ) # includes GL_CULL_FACE

glDisable(GL_CULL_FACE) # draw from all sides

# Size of cone in arrow:

coneFractionAxially = 0.2

coneFractionRadially = 0.1

# Calculate cone parameters:

v = numpy.array((x2-x1, y2-y1, z2-z1))

norm_of_v = numpy.sqrt( numpy.dot(v,v) )

coneHgt = coneFractionAxially * norm_of_v

coneRadius = coneFractionRadially * norm_of_v

vConeLocation = (1.0-coneFractionAxially) * v

# Construct transformation matrix

mat44 = numpy.eye(4)

normalized_v = v/norm_of_v

mat44[0,0] = normalized_v[0]

mat44[1,1] = normalized_v[1]

mat44[2,2] = normalized_v[2]

# -----------------------

# Draw line + cone

# -----------------------

# Draw single line:

glBegin(GL_LINES)

glVertex3f(x1, y1, z1) # from

glVertex3f(x2, y2, z2) # to

glEnd() # GL_LINES

# Move and rotate in position:

glTranslate( *vConeLocation )

if 0: # turn on/off here

#glLoadIdentity()

glMultMatrixf( mat44 ) # <===== PROBLEM HERE?!?! WHAT?

# Make a cone!

cone_obj = gluNewQuadric();

# gluCylinder(gluNewQuadr, Radius_base, Radius_top,

# height, slices, stacks)

gluCylinder(cone_obj, 0, coneRadius,\

coneHgt, 8, 1);

glPopAttrib() # GL_CULL_FACE

glPopMatrix()

As you can see I've made an option to disable using the mat44-matrix. When I disable it, the cone gets drawn but the rotation is wrong. When I enable it, the cone is NOT drawn... Am I multiplying with a wrong rotation matrix and does that explain why nothing gets drawn?

There are no errors/warnings or anything... I don't understand this...