Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Matrix manipulation in DBC

Author
Message
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 6th Jul 2004 12:44
Is it possible to quickly load a matrix file from a bmp (because I don't have dbpro)?I scripted a for next loop that positioned every point in a matrix based on a bmp, i think i did everything right, i didn't sync while loading it, and I only updated matrix after it was all done, but in the end it took about a minute to load a tiny 40x40 image into the matrix so I deleted the code.
Was I doing something wrong? Because if I can get it doing it way faster I am going to try to script a 'seamless' map. So basically as you walk it loads, that way without loading you can have a bloody huge world. Might hurt perfomance considerably, but if it does I will just make the game pause every 100 steps or so to load the area you will soon be walking into, and it shouldn't be that annoying if it loads quickly!
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 6th Jul 2004 23:46
no one knows what i'm talking about?
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Jul 2004 12:45
So you wanna create a matrix based on a heightmap?
Using a greyscale image, this will set the heights of the matrix. This if for dbp unfortunately, and i lost my dbc disc so I can't convert it myself.



"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 7th Jul 2004 19:19
I think i get it...
You are creating the matrix in a memblock, and only updating the matrix once you are done... is the what you are doing? I'v never used memblocks, so i can't really tell... if so, why? Is it faster to do calculations in memblocks?
Rigo
21
Years of Service
User Offline
Joined: 13th Jun 2003
Location: Hungary
Posted: 8th Jul 2004 07:21 Edited at: 8th Jul 2004 07:24
The fastest way:

Make a program, who read the points of the grescale bitmap, and save e.g the rgb red value each points to a simple data file. So, from a 40x40 bitmap you have to get 40x40 value, each from 0 to 255.

And when you make the matrix your main program, then calculate the height from the data file. It takes just some moments.

If you dont understand this explaining, is able to about my bad english...

Mini program source:


Main program matrix loader source:


FZoli.

Look at MED, the Matrix Editor from Hungary! Texture blending, free rts camera, and more!
http://darkbasic.thegamecreators.com/?m=forum_view&t=31490&b=8
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 8th Jul 2004 13:28
how is that any faster than loading the data directly from a bmp? Instead of reading each point and saving to our own format, we just load it directly from the bmp to the matrix... or is DB bad at images so it is way faster loading the exact same data from our own file...?
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jul 2004 16:22
woohoo, i got classic again!

All I had to do from my code above was change the memblock number and now it works in classic. Also, resolution must be 32-bit. A different version must be written for 16-bit.



"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 8th Jul 2004 22:48
I don't understand why this requires memblocks...
Do they make it faster? About how fast for a 10x10 matrix?
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jul 2004 22:53
I'm only using memblocks for the image. It's faster reading the memblock than it is reading the pixel in a bitmap off the screen.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 9th Jul 2004 09:55
um, why? You have to read the image anyway to put it into the memblock, and you use load image so the image is definately in memory...?
Hop a long
21
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 9th Jul 2004 10:03
Really nice code guys! Thanks for sharing. I learned alot and didn't just want to stand here and say nothing.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jul 2004 20:34
Accessing the memblock is like accessing an array.
Using the point() command is very slow.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 10th Jul 2004 20:47
well i get it but it sounds like TGC kind of slacked off with point()!
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 11th Jul 2004 09:10
Phaelax, now that you've got DBC again, mind converting your memblock matrix code? Haha, god of memblocks?

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Jul 2004 12:21
I was going to, but I don't see a way to add vert diffuse colors. If all you want is a basic matrix, I could probably do that.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 12th Jul 2004 16:17 Edited at: 12th Jul 2004 16:19
Okay I am using pro now and I tried your code for dbpro, and it says "Memblock position outside range at line 41" It maybe that i newer versions of dbpro memblocks are from 0 to X, rather than 1 to X... I dunno, got any ideas what the problem could be?

EDIT: I'm going top download my dbpro full version today, so I will get back to you if it still doesn't work...
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Jul 2004 19:22
I just tried it with 5.4, and it works fine for me. Could be something between different images.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 12th Jul 2004 21:52
I just got dbpro 5.4 online and it still doesn't work...
I'll try with different images.
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 12th Jul 2004 22:00 Edited at: 12th Jul 2004 22:02
same problem with the code for classic...
could it have to do with how much memory I have? Because its a memblock command?
From what i understand windows just puts things in hardrive (swap) when it can't fit it in physical memory.
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 13th Jul 2004 16:34
Okay based on the code you sent me, although i still can't get it to work, I made my own code.
I have a 10x10 image called "relief.bmp" in the maps directory. This code is only designed to work with a 10x10 image... but it still doesn't work, and I can't debug it myself because i don't understand memblocks.

load image "maps\relief.bmp", 2
make memblock from image 256,2

for ztile = 0 to 9
for xtile = 0 to 9
location = ztile*10 + xtile*4 + 12
c = memblock byte(256, location)
set matrix height 1,xtile,ztile,c
next xtile
next ztile

Thanks in advanced
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2004 13:20
Are you in 32-bit mode?

And what do the numbers 10 and 4 mean here?
location = ztile*10 + xtile*4 + 12

You might wanna check that line, cause yours is wrong.

((ztile * ix# * ztile_size) + (xtile * iy#)) * 4 + 12

In 32-bit mode, each pixel's color in the memblock takes up 4 bytes. The 12 skips the header in the memblock.

IX and IY is the pixel coordinates in the image that math the matrix tile's coordinates. For IX, divide the image width by the number of matrix X segments. And for IY, divide the image height by the number of matrix Z segments.

Then you got the memblock location for one of the pixel's color components. Unless you want the matrix height to be between 0 and 255, use this equation:

h# = (color*max#)/255.0

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 14th Jul 2004 16:13
because i am using a 10x10 image and a 10x10 matrix, so do i need
((ztile * 10) + (xtile)) * 4 + 12

because ix and iy = 1, and ztile size = 10?

((ztile * ix# * ztile_size) + (xtile * iy#)) * 4 + 12

O and I understand 'h# = (color*max#)/255.0', I just took it out to simplify it while I was debugging it.

I'll see what I can do from your suggestions...
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 14th Jul 2004 16:23
No go...
I can get it to work without crashing by making it ((ztile) + (xtile)) * 4 + 12, but then it doesn't load the image properly...
I need more help, so here is the source code for my whole program so far.

You need the 10x10 bitmap called "Maps\Relief.bmp" in the home directory.

O and there is a lot of pointless stuff in there that i will use in the future, but seeing as you are a pro I am sure you can figure what the relevant suff is...
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2004 17:49
For one thing, you're using memblock number 256, but you can only go as high as 255. Secondly, your matrices are all 10x10 units with 10x10 tiles. Making each tile basically 1 unit big. Also, when setting the height, there are actually 11x11 points to set. You have 0 to 9 for your loops, meaning the last row never gets set.
And exactly why are you creating so many small matrices? Why not make 1 larger matrix?

Change the memblock number to 255. The code basically works, but because the max height is 255, and the matrix is only 10x10, it appears to be completely vertical.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 14th Jul 2004 21:40
I am using lots of small ones so that I can load new areas as you walk, in segments. And I know that each matrix tile has size 1, that was on purpose. But thanks for the help. I get now that 10x10 tiles means 11x11 points.
You are a LEGEND!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2004 22:21
I take it that means you have it working now?

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 14th Jul 2004 22:36
No it means i thought it would... but it isn't working! I replaced all 256's with 255 and no go! And i fixed up the loops so its 0 to 10. HELP! OMG PLZ HELP!
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 14th Jul 2004 22:39
Anyway i have to go to bed now.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2004 22:51
Well if you change the loops to 0 to 10, you need to either make the image 11x11, or add in my equation to adjust the matrix tile number to match the image's pixel number.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 15th Jul 2004 16:29
Okay I have changed the code and image how you have said, it still doesn't work!
First of all, is a 24bit bmp file the problem? Because Paint cannot save in 32-bit color.
Secondly, if I replace ztile*10 with just ztile, it works, but deforms the image.
Perhaps it should be (int(ztile/10)+xtile*10)*4+12 or something like that? Because ((ztile*10) + (xtile)) * 4 + 12 is making location equal a number as high as 446... Which can't be right I assume, seeing as we only go from 0 to 255.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jul 2004 06:43
location doesn't return 0 - 255. It the pixel number of the image. So if you image is 10x10, the highest number would be 336. (9*9*4+12)

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 16th Jul 2004 15:51
Okay I put your code in untouched from load matrix dbpro, and it's loading the image, but again its warping it.

I have supplied the source.

To test it, try make relief.bmp in the maps directory a 11x11 completely black image. Now draw a circle in it using paint. When you test this it does not form a circle in the program.
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 16th Jul 2004 15:54
I just tested it if you get rem randomize matrix in the creation loop, you'll see it does NOTHING!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jul 2004 17:33
I don't know whats wrong, cause I can get it to work.

"eureka" - Archimedes
Doom weaver
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location:
Posted: 17th Jul 2004 08:06
damnit...

Login to post a reply

Server time is: 2025-05-24 22:47:07
Your offset time is: 2025-05-24 22:47:07