simple 3D example - rotating text

Just getting my feet wet with the new features with a single 3D command/feature, rotate.

The example below rotates the text.

function setup()
    displayMode(FULLSCREEN)
    r = 0
    fontSize(32)
end

function draw()
    background(40, 40, 50)
    r = r + 2
    pushMatrix()
    translate(WIDTH/2,HEIGHT/2)
    rotate(r,1,0,0)
    translate(-WIDTH/2,-HEIGHT/2)
    text("Codea 1.3.5",WIDTH/2,HEIGHT/2)
    popMatrix()
end

The above does not work for font sizes above 32. It begins to chop the text.

Likewise with rotate(r,0,1,0) and I assume that the width of text is also limited to 32 for rotation.

As far as I know shapes/sprites would work fine in place of the text.

Also, doing a full 180 rotate works with any fontsize for those who want to make a secret mirror message game.

This is why I love Codea’s technique of 3D. 15 lines of active code to make that. THANK YOU TLL!

I think I am way off somewhere, however. I’ll have to look closer at the real examples tommorow.

Sorry for the multiple posts, but, lightbulb moment. I think I get it … Almost

function setup()
    displayMode(FULLSCREEN)
    r = 0
end
function draw()
    fontSize(WIDTH/16)
    perspective(45, WIDTH/HEIGHT)
    camera(0,300,300, 0,0,0, 0,1,0)   
    background(40, 40, 50)
    r = r + 2
    rotate(r,1,1,1)
    textWrapWidth(fontSize()*5)
    text("Codea 1.3.5",0,0)
end

The reason the text clips at large font sizes is because the default near and far planes of the orthographic projection are -10, and 10 respectively.

By default, Codea sets your scene up with the following parameters:

ortho( 0, WIDTH, 0, HEIGHT, -10, 10 )

Imagine this creates a “cube” around your scene with those dimensions. The last two parameters are the minimum and maximum depths of the cube. Anything that goes outside of those bounds will be clipped. When your text is large, it rotates outside of those bounds.

If you place this line at the start of your draw function:

ortho( 0, WIDTH, 0, HEIGHT, -100, 100 )

The text will no longer clip.

If you actually want perspective effects on the text (gets bigger as it tilts closer to the camera, smaller further away) you can look into using perspective() and camera() instead of ortho().

function setup()
    displayMode(FULLSCREEN)
    r = 0
    s = 900
    font("ArialMT")   
    fill(238, 255, 0, 255)
    t1 = "Episode IV"
    t2 = "A NEW HOPE"
    t3 = "It is a period of civil war. Rebel spaceships, striking"
    t3 = t3 .. " from a hidden base, have won their first victory"
    t3 = t3 .. " against the evil Galactic Empire."
    t4 = "During the battle,"
    t4 = t4 .. " Rebel spies managed to steal secret plans to the "
    t4 = t4 .. "Empire’s ultimate weapon, the DEATH STAR, an armored "
    t4 = t4 .. "space station with enough power to destroy an entire "
    t4 = t4 .. "planet."
    t5 = "Pursued by the Empire’s sinister agents, "
    t5 = t5 .. "Princess Leia races home aboard her starship, "
    t5 = t5 .. "custodian of the stolen plans that can save her "
    t5 = t5 .. "people and restore freedom to the galaxy…."
end
function draw()
    fontSize(WIDTH/20)
    perspective(10, WIDTH/HEIGHT)
    camera(0,2400,10, 0,0,0, 0,1,0)   
    background(40, 40, 50)
    r = r + 2
    --rotate(r,1,1,1)
    rotate(15+180,1,0,0)
    text(t1,0,r+fontSize()*4-s)
    textWrapWidth(fontSize()*15)
    text(t2,0,r+fontSize()*2-s)
    fontSize(fontSize()/2)
    textWrapWidth(fontSize()*12)
    text(t3,0,r-s-fontSize()*12)
    text(t4,0,r-s-fontSize()*24)
    text(t5,0,r-s-fontSize()*36)
end 

http://www.youtube.com/watch?v=7rClFrZkdHk&feature=youtube_gdata_player

Thanks for the explanation.

Awesome. Would be funny to use a Markov Chain over some data source to generate random-but-natural-sounding narrative.

Pretty cool! I think ideally you might want to tweak the field of view a little, so that the crawling text gets smaller the further it gets into the distance?

Very true, there’s many things that can be tweaked for accuracy. After I understood the first bit I slept on it and the old star wars meme came to me as what must be done.

Btw TLL your product needs an addictive/insomnia warning :slight_smile:

Btw TLL your product needs an addictive/insomnia warning

That’s why I requested to bring on the status bar on the editor. I need the clock to be displayed! :smiley:

@Ipda41001 - Like this post I just posted: http://www.flurry.name/zoyt/codea/blog/warning-codea-is-addictive.html
Here’s the image:
here