Render Problem with ARToolkit for a Basket Ball Game

Hello,

I’m working on a basket ball game using ARToolKit. I use a marker to render a basket. And I want to drop a ball in the top of the screen to put it on the basket !
But for the moment, i have a render problem, the ball and the basket doesn’t seems to be on the same render buffer. I have parented these two models to the render.

Here is a screen of the problem :

And here is the code

from pandac.PandaModules import *
from direct.directbase.DirectStart import *
from direct.showbase.DirectObject import DirectObject

class BasketAR(DirectObject):

    def update(self,task):
        if self.cursor.ready():
            self.cursor.fetchIntoTexture(0, self.videoTexture, 0)
            self.toolkit.analyze(self.videoTexture)
        print(self.model.getPos())
        return task.cont

    def __init__(self):

        base.camLens.setNear(0.1)

        #----------------------- Node Common -------------------------
        blankNode = NodePath("blankNode")
        blankNode.reparentTo(render)
        #----------------------- Camera -------------------------
        option = WebcamVideo.getOption(0)
        self.cursor = option.open()
        self.videoTexture = Texture('movie')
        self.cursor.setupTexture(self.videoTexture)
        self.videoTextureScale = Vec2(option.getSizeX()/float(self.videoTexture.getXSize()), option.getSizeY()/float(self.videoTexture.getYSize()))

        #----------------------- Card Maker -------------------------
        cardMaker = CardMaker('cardMaker')
        cardMaker.setFrame(-4/3.0,4/3.0,-1,1)
        cardMaker.setUvRange(Point2(self.videoTextureScale[0],0), Point2(0,self.videoTextureScale[1]))

        #----------------------- Card -------------------------
        card = render.attachNewNode(cardMaker.generate())
        card.setTexture(self.videoTexture)
        card.setTwoSided(True)
        card.setY(5)
        card.setScale(1.72)
        card.setSx(-card.getSx())
        card.setBin("fixed", -1)
        card.setDepthTest(False)
        card.setDepthWrite(False)

        #----------------------- Model -------------------------
        self.model = loader.loadModel("panneau")
        self.model.reparentTo(render)
        self.model.setBin("fixed", 1)
        self.model.setDepthTest(False)
        self.model.setDepthWrite(False)

        #----------------------- self.ball -------------------------
        self.ball = loader.loadModel("basketball")
        self.ball.reparentTo(self.model)

        self.ball.setScale(0.5)
        self.ball.setBin("fixed", 1)
        self.ball.setDepthTest(False)
        self.ball.setDepthWrite(False)
        #----------------------- Move Camera -------------------------
        self.accept("o", base.oobe)

        #----------------------- ARToolKit  -------------------------
        self.toolkit = ARToolKit.make(base.cam, Filename("camera_para.dat"), 1)
        self.toolkit.attachPattern(Filename("patt.kanji"), self.model)

        #----------------------- Task Update -------------------------
        taskMgr.add(self.update, "update")

        #----------------------- Run -------------------------
        run()

BasketAR()

Thank you for your help !

Regards

Just to further diagnose the problem, does it help if you set the window to a square size? (You can do so by altering the win-size variable in C:\Panda3D-1.7.0\etc\Config.prc)

I think there is the same problem… Why using a square screen?

in Config.prc :

win-size 600 600

Here is the result :

Thanks for your help

Hm… this is another wild guess, but does adding the following config variable fix anything: (still using a square window)

textures-power-2 none

It’s the same problem, i think it’s not a texture problem…

dont use:

setDepthTest(False)
setDepthWrite(False)

on ball and ring and it should work.

greetingz!

Thank you very much, it work !

Wow, I totally misunderstood the problem back there. My apologies.

I have an another problem… I would like to flip my video on vertical axis. But when I comment this line :

card.setSx(-card.getSx())

My video is fliped but the 3d object doesn’t follow the tracker. When my tracker is on left my object is on right and vice versa.

Try:

base.cam.setSx(-1)
render.setAttrib(CullFaceAttrib.makeReverse())

The first scale mirrors everything the camera sees, which also incidentally turns objects inside-out (because it changes the vertex winding order).

The second call corrects for the inside-out effect.

David

I add your code but the problem persist :

Thanks for your help

Regards

Did base.cam.setSx(-1) flip the display, or did it fail to have any effect at all? Did you remember to remove your scale from the card? (Flipping the camera should flip both the card and the 3-D graphics; it is unnecessary to flip the card separately.)

David

I add your lines :

base.cam.setSx(-1)
render.setAttrib(CullFaceAttrib.makeReverse())

And i have remove the Sx on my card. My image is not flip. I would like to have a mirror effect. Here when i go at left i go at right on my screen…

Hi all i have the same problem, and i not find solution here. I can solve with trasformations, hope it helps.

— on init —
#Flip webcam image
card.setSx(-card.getSx())

—on update frame—
#get ar position al location
pos = axis.get_pos()
rot = axis.get_quat()

#set flipped location and rotation
np.setPos(-pos[0],pos[1],pos[2]);
np.setQuat( LQuaternionf(-rot[0],-rot[1],rot[2],rot[3]) );

TY a lot