Author Topic: Texture drawing  (Read 38386 times)

0 Members and 3 Guests are viewing this topic.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Texture drawing
« on: June 13, 2011, 04:29:29 pm »
Does anybody knows how to draw repeated textures? It would help a lot at my 3D engine, which now can only render wireframe.

I only need to know how it's done, so I can write my own routine.

What I mean with textures: this is a wire frame rectangle rendered by my 3D Engine:

I want to draw a sprite between those 4 points. Could someone explain the principle behind this please?
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #1 on: June 13, 2011, 05:35:20 pm »
There's only one person I can think of that has ever done that, he made Gemini. Looking through the source of that, you could probably figure out how he did it.

At the moment, I can think of some ways to do it, but I'm not sure they would be fast.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Texture drawing
« Reply #2 on: June 13, 2011, 06:59:02 pm »
Well Gemini was a raycaster, not a "real" 3D engine. Which I believe is what ben_g wants. Applying textures in raycasting is easy because of the vertical scanline rendering method and the restrictions of the camera.
« Last Edit: June 13, 2011, 07:00:02 pm by Runer112 »

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Texture drawing
« Reply #3 on: June 13, 2011, 06:59:59 pm »
So is this just a horizontal engine? No looking up or down?
In-progress: Graviter (...)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Texture drawing
« Reply #4 on: June 13, 2011, 08:10:42 pm »
Hmm I haven't seen any 3d polygon game with textures on calculators yet. I wonder if it would achieve sustainable speed like in Runer112's raycaster?

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Texture drawing
« Reply #5 on: June 13, 2011, 08:12:29 pm »
Look for wolfenstein castle.

EDIT: http://www.ticalc.org/archives/files/fileinfo/277/27767.html

Hella awesome.
In-progress: Graviter (...)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Texture drawing
« Reply #6 on: June 13, 2011, 08:16:37 pm »
That's a raycaster too actually, like Gemini.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Texture drawing
« Reply #7 on: June 13, 2011, 08:18:17 pm »
Oh you said polygon. Never mind.
In-progress: Graviter (...)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Texture drawing
« Reply #8 on: June 14, 2011, 02:25:37 am »
The only project I have ever seen that used linear interpolation across polygons was a space shooter thingy from maxcoders but it was limited, and that was in asm.  The method used is called linear interpolation, and I have a really good website that explains it, but it's on my other computer, so i will have to post it later.  Let me say though, that this is not an easy task, and even the most optimized engines will take lots of memory and barely be able to handle too many polygons.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #9 on: June 14, 2011, 07:27:37 am »
Well Gemini was a raycaster, not a "real" 3D engine. Which I believe is what ben_g wants. Applying textures in raycasting is easy because of the vertical scanline rendering method and the restrictions of the camera.
Yes, It's a "real" 3D engine, and it supports both vertical and horizontal rotation, as well as letting the camera rotate along it's axis using the up vector. There's no way to use routines from raycasters for this. I've already checked gemini, and it renders by casting rays, not by calculating the location of points and drawing a texture between them.

btw: what would be the easyest? Drawing a texture on the quad or drawing a quad as two textured triangles? (Triangles are used with 3D on a computer, But I don't know which is the fastest)
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Texture drawing
« Reply #10 on: June 14, 2011, 07:32:50 am »
[offtopic] Congrats ben_g: 100th post !
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #11 on: June 14, 2011, 11:09:41 am »
Ok, here is my method. I'm literally making it up as I write this post, but in the end it should work. For this you should use triangles.

1. Convert the 3 corners to xy coordinates.
2. Calculate the relative size of the leftmost point. (3d window distance thing / distance)
3. Now calculate the relative size of each of the other two points and subtract the original from them.
4. (This is where it gets sketchy) You need to figure out the two slopes of (relative distance) / x = a and (relative distance) / y = b. Right now you have two equations: d1 = ax1 + bx1 and d2 = ax2 + bx2. So you need to solve those for a and b. I would divide the first equation by x1, then subtract the the second equation from the first. the ax's will cancel and you can get b. Then just substitute b and get a.
5. Now to apply the texture, we have to base the texture somewhere, so you should probably put the leftmost point on the left side of the texture dead centered vertically.
6. To calculate the pixel in the texture to use for a screen coordinate, here is what you do. X = (1 / (screenOffsetX * a + relativeSizeOfLeft) * screenOffsetX / totalXWidth * textureWidth) and Y is the same.
7. Then, take that pixel out of the texture and put it on the screen.

As far as I can tell, that should work. I'm sure if you actually do it, you'll find lots of optimizations. For instance, the reciprocal I forgot about at the end could probably be calculated earlier.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #12 on: June 14, 2011, 01:33:14 pm »
Ok, here is my method. I'm literally making it up as I write this post, but in the end it should work. For this you should use triangles.
...
2. Calculate the relative size of the leftmost point. (3d window distance thing / distance)
3. Now calculate the relative size of each of the other two points and subtract the original from them.
...
Could you please explain what you mean by the size of a point?

[offtopic] Congrats ben_g: 100th post !
Thanks. 100 post sure goes by fast. I didn't knew I was already there :P
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #13 on: June 14, 2011, 01:55:25 pm »
Ok, you can use this page and this page for pictures.

What you are trying to do is to figure out how tall the wall should be on the actual screen. The concept we are using here is that an object that is twice as far from you will look half the size. So we can see that the equation would be size = k/distance. Now the question is of course, what is k.

K is the distance to the projection screen. The way you calculate this, you can see in that first link I gave you. It is (screenWidth / 2) / tan(fieldOfView / 2). So assuming you are using a 60 degree field of view on the calculator. 48/tan(30) = 83.

Now go to the second link. What this means, is that a wall on screen that is 83 units away, will be it's actual size. 166 units away it will be half its size, 41.5 units away it will be double size.

So the formula is now (relative size) = 83/distance. Which means if your sprite is supposed to be 50 pixels tall, when it is 120 units away, it will be 83/120 * 50 = 34.5 pixels tall.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #14 on: June 14, 2011, 02:17:33 pm »
Isn't it much easier to calculate how tall the wall is by calculating the distance between the upper point and the lower point? I already convert points from 3D to 2D, so won't it be faster when the textures are calculated to just fit between those points? Triangles have more possibilities, so I think triangles are the best choice, but if I can calculate the slope and size of all 3 sides, isn't that enough to apply a texture?
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated