Author Topic: Coding Help  (Read 14536 times)

0 Members and 1 Guest are viewing this topic.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Coding Help
« on: October 07, 2011, 12:23:59 AM »
So, the "What are you working on" topic is getting very overused for all of my coding issues, and does not relly fit into anywhere else than in the "Off Topic" section, so I made a topic for my(probbably yours too?) coding problems.

Quote from: Problems
Current Problems for me:

I want to know how to locate a position in 3d from 2d, like clicking on a block in 3d with the mouse. Like demonstrated in this picture:

Lets also say that the mouse is free(not centered) and will not move the player rotation, we need to find it with only the knowledge of the players rotation and the position of both the block and mouse!



(Old Minecraft version :o)

I got another problem, in java. I need to make a bitmap, like in Minecraft(I'm doing alot of examples from Minecraft :D) where the textures are 16x16, but inside a 256x256 image. So it's split up to 16x16 and given texture IDs, then used to texturize the blocks. So I was wondering if iyou know how to do this(I'll solve it myself, but help would make it  go faster :))
« Last Edit: October 08, 2011, 02:22:45 AM by Aino »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 23
  • Posts: 930
  • Eufloria: Yes
Re: Coding Help
« Reply #1 on: October 07, 2011, 01:09:22 AM »
I could tell you the maths behind it if you want...

Assuming the block is on the screen, then just check if the point (X, Y) that describes the coordinates of the mouse's click on the screen with the area defined by the edges of the cube. Make sense, or do you want me to explain more?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Re: Coding Help
« Reply #2 on: October 07, 2011, 02:36:30 AM »
Explain more :D

The maths, everything!

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 23
  • Posts: 930
  • Eufloria: Yes
Re: Coding Help
« Reply #3 on: October 07, 2011, 05:46:15 AM »
Topmorrow, then, or maybe a bit later. Watch this space.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Re: Coding Help
« Reply #4 on: October 08, 2011, 02:19:28 AM »
I willl, I got another problem too though, I think I can solve that myself, not much to do with programatic math :P

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 23
  • Posts: 930
  • Eufloria: Yes

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Re: Coding Help
« Reply #6 on: October 10, 2011, 06:31:45 AM »
Pilchard, you're always to help :D

Thx alot :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Re: Coding Help
« Reply #7 on: November 04, 2011, 11:24:39 PM »
Pilchard, would be useful with some info on the mouse/3d pos thing, maybe a website I can see or something? :P

Mihhaelo

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 67
Re: Coding Help
« Reply #8 on: November 10, 2011, 06:38:50 PM »
Hey :P Would be awesome if someone could explain this to me.

In eufloria if i type this I get an error! (invalid arguments to method call). But the Lua interpreter doesn't have issue with it.

Code: [Select]
queue = ()
queue[1] = 1
queue[2] = 2
queue[3] = 3
queue[4] = 4
queue[5] = 5

for i,v in ipairs(queue) do print(i,v) end

At first I thought Eufloria was taking issue with the comma, since I can avoid the crash by using a concatenation. This made me think that maybe Eufloria was using an older version of lua.

I then typed this however, which in my mind is the exact same as the first code and it works!

Code: [Select]

g = function(n) print(n) end

for i,v in ipairs(queue) do g(i,v) end

What is the difference between the two bits of code? And why can't I use the comma in the first?

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 23
  • Posts: 930
  • Eufloria: Yes
Re: Coding Help
« Reply #9 on: November 11, 2011, 01:38:03 AM »
No idea, though I'd recommend changing the first line of code 1 to

queue = {}

Curly braces.

Mihhaelo

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 67
Re: Coding Help
« Reply #10 on: November 11, 2011, 01:57:28 AM »
I guess that's an example of why it's better to copy/paste code instead of typing it into forums  ;D

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 23
  • Posts: 930
  • Eufloria: Yes
Re: Coding Help
« Reply #11 on: November 12, 2011, 06:51:50 AM »
Terribly sorry, Aino, RL got in the way. Regarding your 3d-2d click problem, the way I'd go about it is as follows:

You know where the objects are, yes? Of course you do, otherwise you couln't render them. Take this data, and every time a mouse click is registered, compare its position against the block position data. You should be able to work out which was clicked from that.

If that doesn't work try adding a mouse listener to each graphic object.

Ofc, without knowing specifics, I can't really be much more help. Wish there was more activity here, it's kinda sad atm. Roll on the patch.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Re: Coding Help
« Reply #12 on: December 06, 2011, 12:17:44 AM »
Hey, I need some help again: I need to know where you are looking, first person 3d perspective, like in minecraft.
I need to know which block you're currently looking at, or at least how you calculate it.

Darkzlime

  • Seed
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
Re: Coding Help
« Reply #13 on: December 06, 2011, 01:44:55 AM »
You could use some kind of hitbox system, i have one for 2d games

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 5
  • -Receive: 30
  • Posts: 1,528
  • They'll eat you next!
  • Eufloria: Yes
Re: Coding Help
« Reply #14 on: December 06, 2011, 03:03:50 AM »
Sounds very useful for what I need, but how do I make it recognize it being hit? I think I should make a for loop that checks through all the lengths?