[SOLVED] CG - Geometry Instancing - Rotation

Hi guys,

I’m using CG to try out some geometry instancing, the passing of an instance position to the shader via an array works ok, but how does one change the rotation of an instance?

I’m not sure if a 4x4 matrix needs to be supplied, or if I can pass the shader an HPR and it’ll do the transform.

I’ve been using the examples here:

The flocking example SEEMs to pass matrices, but couldn’t get that one to work. Any pointers?

It’s probably easiest to pass a transformation matrix, which gets you all transformation components (position, hpr, scale, shear).

I couldn’t get 4x4 matrix arrays to work either. I ended up pulling the rows out of each matrix and packing it into a PTA_LVecBase4f.

When I try to run the flocking example, I get a TypeError (inappropriate arguments) at the setShaderInput line of:

self.modelViewMatrices = [modelMatrix * self.viewMatrix for modelMatrix in self.modelMatrices]
self.ralph.setShaderInput('p3d_modelviews', self.modelViewMatrices)

Is that the same error everyone else is getting?

(dev build 93, Windows 7, Nvidia GTX 570)

Stone the flaming crows, after fiddling around for 2 hours - I’ve got it working with the flocking demo :smiley:

Try this:

    # Compute the modelview matrix for each node 
    self.modelViewMatrices = [UnalignedLMatrix4f(modelMatrix * self.viewMatrix) for modelMatrix in self.modelMatrices]

If you want to enable the camera moving, you’ll need to reset the viewMatrix in the IssueShaderParameters function.

I might end up cutting this down to a sample thats just the basics, thanks for the help :slight_smile:

It works. Thank you very much. :slight_smile: