Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I've been looking all over, but all I've been able to find are lists of the gu functions, with no ...
-
03-10-2007, 10:54 AM #6031Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I found this very useful
Check This OutI've been looking all over, but all I've been able to find are lists of the gu functions, with no info on what each one does or how to use them.
Can someone explain how this works, and what I would need to do to make it display a tile image instead of a red square?
-
03-10-2007, 12:58 PM #6032
Thanks! I've read through that and now I understand a little bit about what the functions do, but unfortunately not enough to to what I want.
-
03-10-2007, 01:18 PM #6033Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
what do you want to do ?
-
03-10-2007, 02:00 PM #6034
I'm making a program to edit 2d tile maps. Right now, I've got it set up to use KleptoOne's image rotate function to rotate the tiles. However, since it uses the math 2d image functions, in order to keep it from slowing down the program I have to have it create the rotated version of the images and save them into an array as I load them. While this method works, it multiplies the amount of memory the tiles use by 4, which in turn puts a smaller limit on the number of images that can be loaded. Also, the rotated images have small errors in them - shapes get slightly distorted and sometimes one or more of the edges will have a row of blank pixels.
What I'd like to to is change my graphics display setup so that it can use the 3d GU to display the tiles and rotate them on the fly, which will be faster and use less memory. It's the last thing I want to figure out before making my initial release for the editor. Also, when I get my map editor working, it will not only make it easer to make maps, but I'll also be able to use the code for the graphics display in a game engine.
On evilmana, I found thread where Soulkiller posted his GU library
http://forums.evilmana.com/index.php...sg5049#msg5049
The draw2d function looks like it should be able to do what I want, but when I used it in a test program all I got was a black screen:
Code:a = Image.load("1.png") p = {} p[1] = 50 p[2] = 50 p[3] = 0 r = {} r[1] = 0 r[2] = 0 r[3] = 0 function Gum.draw2d(pos,rot,image) local white = Color.new(255,255,255) local square = { {0, 0, -1, -1, 0}, -- TOP LEFT {1, 0, -1, 1, 0}, -- BOTTEM LEFT {0, 1, 1, -1, 0}, -- BOTTEM RIGHT {1, 1, 1, 1, 0}, -- TOP RIGHT } Gu.start3d() Gum.matrixMode(Gu.PROJECTION) Gum.loadIdentity() Gum.perspective(5, 16/9, 0.5, 1000) Gum.matrixMode(Gu.VIEW) Gum.loadIdentity() Gum.matrixMode(Gu.MODEL) Gum.loadIdentity() Gum.translate( pos[1], pos[2], pos[3]) Gum.rotateXYZ( rot[1]/57.295779513, rot[2]/57.295779513, rot[3]/57.295779513) Gu.enable(Gu.TEXTURE_2D); Gu.texImage(image) Gu.texFunc(Gu.TFX_MODULATE, Gu.TCC_RGBA) Gu.texFilter( Gu.NEAREST, Gu.NEAREST ) Gu.texScale(1, 1) Gu.texOffset(0, 0) Gum.drawArray(Gu.TRIANGLE_STRIP, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, square); Gu.end3d(); end while true do screen:clear() Gum.draw2d(p,r,a) screen.flip() pad = Controls.read() if pad:left() and pad ~= oldpad then r[1] = r[1] + 90 end if pad:right() and pad ~= oldpad then r[1] = r[1] - 90 end if Controls.read():start() then break; end oldpad = pad end
-
03-10-2007, 03:07 PM #6035Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hmm
I can't seem to get your code to work, but I worked out simular code using the tutorial I showed you. Maybe you can play around with this and use it.
Analog stick rotates image, circle, triangle zooms in and out. I also have some stuff in there for a racing game I'm woking on, x to accelerate, square to brake and reverse. (Not really relevant, but just in case you get confused)
Code:white = Color.new(255,255,255) red = Color.new(255,0,0) dred = Color.new(125,0,0) blue = Color.new(0,0,255) green = Color.new(0,255,0) gray = Color.new(153, 153, 153) dgrey = Color.new(53, 53, 53) colors = {} colors[1] = white colors[2] = red colors[3] = blue colors[4] = green colors[5] = gray textureimg = Image.load("1.png") c = 1 pitch = 0 yaw = 0 roll = 0 x = 0 y = 0 z = -5 r = 0 newx = 0 newy = 0 while true do block2 = { {.5,.5,colors[c],0,0,0}, {0,0,colors[c],-1,1,0}, {1,0,colors[c],1,1,0}, {0.5,0.5,colors[c],0,0,0}, {1,0,colors[c],1,1,0}, {1,1,colors[c],1,-1,0}, {0.5,0.5,colors[c],0,0,0}, {1,1,colors[c],1,-1,0}, {0,1,colors[c],-1,-1,0}, {0.5,0.5,colors[c],0,0,0}, {0,1,colors[c],-1,-1,0}, {0,0,colors[c],-1,1,0}, } screen:clear() pad = Controls.read() Gu.start3d() --clear everything out: Gu.clearDepth(0); Gu.clear(Gu.COLOR_BUFFER_BIT+Gu.DEPTH_BUFFER_BIT) --setup viewing: Gum.matrixMode(Gu.PROJECTION) -- camera mode Gum.loadIdentity() Gum.perspective(50, 16/9, 0.5, 1000) --Sets up the look perspective Gum.matrixMode(Gu.VIEW) -- sets model mode Gum.loadIdentity() --goes into model mode Gum.matrixMode(Gu.MODEL) Gum.loadIdentity() Gu.enable(Gu.BLEND) Gu.blendFunc(Gu.ADD, Gu.SRC_ALPHA, Gu.ONE_MINUS_SRC_ALPHA, 0, 0) Gu.enable(Gu.TEXTURE_2D); Gu.texImage(textureimg) Gu.texFunc(Gu.TFX_MODULATE, Gu.TCC_RGBA) Gu.texEnvColor(white) Gu.texFilter(Gu.LINEAR, Gu.LINEAR) Gu.texScale(1, 1) Gu.texOffset(0, 0) Gu.ambientColor(white) Gum.matrixMode(Gu.MODEL) Gum.loadIdentity() Gum.translate(x, y, z); Gum.rotateXYZ(pitch * (Gu.PI/180), yaw * (Gu.PI/180), roll * (Gu.PI/180)) Gum.drawArray(Gu.TRIANGLES, Gu.TEXTURE_32BITF+Gu.COLOR_8888+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, block2) --end 3d: Gu.end3d() newx = math.ceil(r*math.cos((roll-90) * (Gu.PI/180))) newy = math.ceil(r*math.sin((roll-90) * (Gu.PI/180))) x = x + (newx/1000) y = y + (newy/1000) screen:print(10, 10, "x " .. x, white) screen:print(10, 20, "y " .. y, white) screen:print(10, 30, "z " .. z, white) screen:print(10, 40, "pitch "..pitch, white) screen:print(10, 50, "yaw " .. yaw, white) screen:print(10, 60, "roll " .. roll, white) screen:print(10, 70, "r " .. r, white) screen.waitVblankStart(1) screen.flip() if pad:up() then pitch = pitch + 1 if pitch > 359 then pitch = 0 end end if pad:down() then pitch = pitch - 1 if pitch < 0 then pitch = 359 end end if pad:l() then roll = roll + 4 if roll > 359 then roll = 0 end end if pad:r() then roll = roll - 4 if roll < 0 then roll = 359 end end if pad:left() then yaw = yaw - 1 if yaw < 0 then yaw = 359 end end if pad:right() then yaw = yaw + 1 if yaw > 359 then yaw = 0 end end if pad:analogX() > 50 then roll = roll - 4 if roll < 0 then roll = 359 end end if pad:analogX() < -50 then roll = roll + 4 if roll > 359 then roll = 0 end end if pad:analogY() > 30 then end if pad:analogY() < -30 then end if pad:cross() then r = r - 2 else if r < 0 then r = r + 2 end end if pad:triangle() then z = z + .1 end if pad:select() then r = r + 1 screen.waitVblankStart(10) end if pad:square() then if r >= 0 then r = r + 1 elseif r < 0 then r = r + 4 end elseif r > 0 then r = r - 2 end if pad:circle() then z = z - .1 end if pad:start() then while pad:start() do pad = Controls.read() end screen:clear() break end end
-
03-10-2007, 03:36 PM #6036
Thanks, that's cool. It does a little more than I need atm, so I'll have to mess around with it a bit to see what I can take out
-
03-10-2007, 03:47 PM #6037Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Kleptoone
Yeah, I just copied the source as is for my project without trimming it up. But the function you were looking to create is in there so you should be able to put something together. Let me know if you have any questions.
-
03-10-2007, 04:34 PM #6038
two questions:
First, does it really need to have the colors codes in array for the model description?
And second, although I've trimmed it down to use only the 1/4, 1/2, and 3/4 rotations I need, it resizes the tiles - smaller tiles become bigger, larger tiles become smaller. What do I need to do to display the tile in it's original size?Geändert von Merick (03-10-2007 um 04:51 PM Uhr) Grund: Automerged Doublepost
-
03-10-2007, 04:52 PM #6039Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
actually no, if you take that statement out then just make sure you change your draw command to:
editCode:Gum.drawArray(Gu.TRIANGLES, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, block2)
Give me a few on the second question
-
03-10-2007, 04:59 PM #6040
hmm.. I took the colors out and put in the new draw command, but it gives me the error "wrong number of vertex components"
Code:white = Color.new(255,255,255) red = Color.new(255,0,0) dred = Color.new(125,0,0) blue = Color.new(0,0,255) green = Color.new(0,255,0) gray = Color.new(153, 153, 153) dgrey = Color.new(53, 53, 53) colors = {} colors[1] = white colors[2] = red colors[3] = blue colors[4] = green colors[5] = gray textureimg = Image.load("link.png") c = 1 pitch = 0 yaw = 0 roll = 0 x = 0 y = 0 z = -5 r = 0 newx = 0 newy = 0 block2 = { {.5,.5,0,0,0}, {0,0,-1,1,0}, {1,0,1,1,0}, {0.5,0.5,0,0,0}, {1,0,1,1,0}, {1,1,1,-1,0}, {0.5,0.5,0,0,0}, {1,1,-1,0}, {0,1,-1,-1,0}, {0.5,0.50,0,0}, {0,1,-1,-1,0}, {0,0,-1,1,0}, } while true do screen:clear() pad = Controls.read() Gu.start3d() --clear everything out: Gu.clearDepth(0); Gu.clear(Gu.COLOR_BUFFER_BIT+Gu.DEPTH_BUFFER_BIT) --setup viewing: Gum.matrixMode(Gu.PROJECTION) -- camera mode Gum.loadIdentity() Gum.perspective(50, 16/9, 0.5, 1000) --Sets up the look perspective Gum.matrixMode(Gu.VIEW) -- sets model mode Gum.loadIdentity() --goes into model mode Gum.matrixMode(Gu.MODEL) Gum.loadIdentity() Gu.enable(Gu.BLEND) Gu.blendFunc(Gu.ADD, Gu.SRC_ALPHA, Gu.ONE_MINUS_SRC_ALPHA, 0, 0) Gu.enable(Gu.TEXTURE_2D); Gu.texImage(textureimg) Gu.texFunc(Gu.TFX_MODULATE, Gu.TCC_RGBA) Gu.texEnvColor(white) Gu.texFilter(Gu.LINEAR, Gu.LINEAR) Gu.texScale(1, 1) Gu.texOffset(0, 0) Gu.ambientColor(white) Gum.matrixMode(Gu.MODEL) Gum.loadIdentity() Gum.translate(x, y, z); Gum.rotateXYZ(pitch * (Gu.PI/180), yaw * (Gu.PI/180), roll * (Gu.PI/180)) -- Gum.drawArray(Gu.TRIANGLES, Gu.TEXTURE_32BITF+Gu.COLOR_8888+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, block2) -- Gum.drawArray(Gu.TRIANGLES, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, block2) --end 3d: Gu.end3d() newx = math.ceil(r*math.cos((roll-90) * (Gu.PI/180))) newy = math.ceil(r*math.sin((roll-90) * (Gu.PI/180))) x = x + (newx/1000) y = y + (newy/1000) screen:print(10, 10, "rotation in deg " .. roll, white) screen.waitVblankStart(1) screen.flip() if pad:left() and pad ~= oldpad then roll = roll + 90 if roll > 270 then roll = 0 end end if pad:right() and pad ~= oldpad then roll = roll - 90 if roll < 0 then roll = 270 end end if pad:start() then while pad:start() do pad = Controls.read() end screen:clear() break end oldpad = pad end
-
03-10-2007, 05:04 PM #6041Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
3rd triangle you deleted one of the points should be:
as for the sizing, its tricky as the z will define your block size, but if you set it to -9.2 it should be the same size as the original.Code:{0.5,0.5,0,0,0}, {1,1,1,-1,0}, {0,1,-1,-1,0},
-
03-10-2007, 05:25 PM #6042
Ahh, and I also deleted one out of the fourth block too. As for the Z, changing it to -9.5 only make the images smaller. I'll need to figure out some kind of algorithm to change the z based on the size of the image.
-
03-10-2007, 05:35 PM #6043Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
yeah i was eyeballing it, i'll see if I can work one out, if you beat me would you mind posting it?
-
03-10-2007, 05:55 PM #6044
hmm.. In 3d mode, does the x,y position change to the center of the screen instead of the upper left corner like in 2d?
-
03-10-2007, 06:22 PM #6045Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
yeah, the coordinate system is completely different then 2d. I'm trying to find some good resources on the conversion.
-
03-10-2007, 07:06 PM #6046
I'm having problems compiling the luaplayer 0.20 source.
It compiles without errors (or even warnings) but the eboot just crashes my psp.
if i could get it to compile, it would be a walk in the park to add ortho support.
-
03-10-2007, 07:16 PM #6047lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Compiling LUA Player should be n the C/C++ help thread.
-
03-10-2007, 07:23 PM #6048words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
eyece - I got it to compile fine. You may not be compiling correctly... First, make sure you have all the libraries needed installed. When i tried my first time, i needed to install freetype, lualib,lua, and mikmod (mikmodlib wouldnt install i think, so i installed libmikmod). Than, you need to:
If your getting ready for release, do make release10 or make release15Code:make clean-all make

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
03-10-2007, 08:02 PM #6049
i think im going to have to reinstall cygwin, is the size of the elf/pbp 1,234KB when you guys compile it?
-
03-10-2007, 08:13 PM #6050words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
eyece - Depends. My mod of luaplayer is like 1,389 kb or somethin...
BTW - why do you want to compile lua player ;)
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
03-10-2007, 09:37 PM #6051
KleptoOne wanted to draw stuff in 2D, ortho would be the best option, but its not supported yet. i was going to add it.
-
03-10-2007, 09:43 PM #6052QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Alabama
- Beiträge
- 142
- Points
- 4.241
- Level
- 41
- Downloads
- 0
- Uploads
- 0
You are adding it to Cools' mod or SG57's Cools' mod, right?
-
03-11-2007, 04:48 AM #6053
btw whats ortho?
-
03-11-2007, 07:48 AM #6054QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
http://www.youresam.com/tutorials/layout.PNG
Zitat von KleptoOne
-
03-11-2007, 03:26 PM #6055words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
The coordinate system isn't all that different, nor hard to adjust to... Just an inverted Y axis. Plus, if you just scale your entire scene -1 on the y axis, youll have the same coordinate system as your used to.
emerica - Short for orthogonal-projection. Mainly used to incorporate 2D into your program. This will draw your shape in a space that will not move when your 3D scene is rotated. This is perfect when implementing a display system into your game that displays health, ammo, etc.
If you want, ill post a quick PSPGL example of how to start/stop an orthogonal projection. Theres GU equivalent functions, but youd have to search for em' ;)
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
03-11-2007, 04:53 PM #6056
thanks for the clarification, i don't care if you do that or not right now, because i know no 3-D yet anyway.
-
03-12-2007, 01:55 AM #6057.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
I've seen it before, but i'm not sure how to do it; how can i get the filesize of something and return it as a string?
-
03-12-2007, 02:28 AM #6058
I haven't tested it, but this bit of code should set up fileInfo as a table with a file list for the specified directory. fileInfo[number].filename to get the filename, fileInfo[number].filesize to get the file size. Alternately, if you already know the exact filename that you are looking for, you can can set up your loop to scan the files array to look only for that filename, and then get the filesize for that file only:Code:files = System.listDirectory(directory name) fileInfo = {} count = 1 for i = 3, table.getn(files) if files[i].directory == false then fileInfo[count] = {filename = files[i].name, filesize = files[i].size} count = count +1 end end
with either, I think that the file size that will be returned will be a number value, but you can use tostring to convert it to a string if you really need toCode:for i = 3, table.getn(files) if files[i].name == "filename" then filesize = files[i].size end
Geändert von Merick (03-12-2007 um 02:38 AM Uhr)
-
03-12-2007, 09:53 PM #6059.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
So basically if i get the directory listed in a table, and search the table for blah[blah].size, it should return the value?
-
03-13-2007, 02:42 AM #6060
Yeah, basically. There might be an even easier way, but if so I haven't found it yet.


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum