Python Forum
How to find the location of an object and object at a given location?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find the location of an object and object at a given location?
#1
I have two question

1)how to find the object given the location of the object?

Let's say I draw a cube at coordinate x y z ,4 5 3 respectively.
I want Python to print "cube" when I search the coordinate 4,5,3.
How would I do it?
I can use a variable to keep track the coordinate of every object in the game,but I have infinite amount of object generated in the game scene(using infinite procedural generation)

2)how to find the location of the object given the object name?

Note:I am using OpenGL 
Note2:there must be something in OpenGL(or pygame) I can use to keep track of the location of all object in the game scene.
Is there?
Reply
#2
Quote:there must be something in OpenGL(or pygame) I can use to keep track of the location of all object in the game scene.
in pygame you would just use pygame.rect to keep track of each objects location. You dont need to keep track of everythings location, as you would just check if that suspected object's rect collided with another objects rect. And if so they are close enough to do a mask check or consider they collided. 

Quote:Let's say I draw a cube at coordinate x y z ,4 5 3 respectively.
I want Python to print "cube" when I search the coordinate 4,5,3.
How would I do it?
When you search the coordinate with what? The mouse? Again in pygame it would use rects. If the mouse in the rect then the mouse is in those coordinates.

I think for a better answer, we would need a code snippet. Or a detailed input/output of what you want.
Recommended Tutorials:
Reply
#3
(Jan-29-2017, 05:33 AM)metulburr Wrote: I think for a better answer, we would need a code snippet. Or a detailed input/output of what you want.

I exactly don't know how to do ,that is why I am here.

Here is a pseudocode of what I want to do:


Use opengl to draw the block(example:grass) a location(example:1 (x axis),5(y axis),4(z axis)
Store the location of the grass object in a dictionary/variable(grass={x:1,y:5,z:4}}
Search a location(example:search(x=1,y=5,z=4))
Then,print the object name at the given location in the search(in this case,grass)
But I have infinite object in my scene,do I need to create infinite amount of vaariable?(which is impossible)

Don't forget I am using pygame and OpenGL .
Reply
#4
Quote:But I have infinite object in my scene,do I need to create infinite amount of vaariable?(which is impossible)
I am not sure about opengl...i have never used it. But i am pretty sure that 2d and 3d rendering is not much different when it comes to structure. You can have unlimited 2d objects as well. However you cannot have unlimited number of anything when it comes to computers. You will run out of space at some point. 

Have you done 2d simple scrolling backgrounds, tile backgrounds for things like top-down RPG's? It seems like you are jumping the gun if you have not. Much of what i read is you have to fully understand and make simple 2d games before taking on a much larger role of 3d. Which i am assuming you are doing because of having 3-dimensional coordinates. At the same time it appears you are asking a question that is from someone who has yet made 1 game ever.
Recommended Tutorials:
Reply
#5
Everything you said in your last post is absolutely true,but I need to jump to advanced stuff because it will waste my time by staying or doing easy stuff.
In other words,I want to rush so I can do more advanced thing with python in the future.

Note:I am just a 15 years old boy,that does not know add math or physic yet,and I will be having pt3 this year too.
Reply
#6
Quote:,but I need to jump to advanced stuff because it will waste my time by staying or doing easy stuff.
Everyone needs to start at the beginning. You are trying to understand calculus while bypassing trig and algebra. Your trying to build a house without ever having built a wall or put in an electrical outlet. etc. etc. Its just not going to fly. For example, you should already have some ideas on how to go about your question, even if it is not the best approach. But you do not because you never have done the basics. 

I would suggest to put on hold what you are doing and do some basic 2d pygame only stuff. Make a couple games beforehand, like RPG top-down with a tile manager, a platformer like mario, etc. Give them the full works, like a menu system, multiple levels, level editor, add your own mechanics like stabyourself did with mario, etc.. These will get you the basics. After you are done with these you will not need to ask this question.
Recommended Tutorials:
Reply
#7
(Jan-29-2017, 06:05 PM)metulburr Wrote: You should already have some basic ideas on how to go about your question,even if it is not the best approach.But you do not because you never have done the basic.

I have the basic idea,but I am just not sure whether it is possible or not

Basic idea:
Creating a variable and save it to a file whenever a new object is created in the scene to store the object current location. Smile Big Grin 

Is it possible?
How do I do it?
Reply
#8
No because reading/writing to the hard drive is one of the slowest operations. If you did this your game would be laggy.
Recommended Tutorials:
Reply
#9
(Jan-30-2017, 12:50 PM)metulburr Wrote: No because reading/writing to the hard drive is one of the slowest operations. If you did this your game would be laggy.

What if I store all object's location in the variablesssssssss first,then write it to the file only when the player save and quit the game?
Possible?

How?

The main thing I want to know is how to procedurally create variable name and assign the value to it,please?
Maybe after you answer this question,I can figure out how to solve it myself.
Reply
#10
(Jan-30-2017, 01:51 PM)hsunteik Wrote: How?
https://docs.python.org/3.6/tutorial/inputoutput.html
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Rect object penetrates wall on one side Jan_97 4 2,549 Dec-30-2021, 11:08 PM
Last Post: Jan_97
  [PyGame] object has no attribute 'add_internal' djwilson0495 7 8,088 Feb-26-2021, 05:06 PM
Last Post: nilamo
  Location of the objects that are moving rturus 1 2,162 Feb-01-2021, 05:44 PM
Last Post: nilamo
  [PyGame] why the position of the object is different? syafiq14 1 1,945 Nov-24-2020, 03:22 PM
Last Post: metulburr
  [PyGame] object's movement to left leave shadow on the screen Zhaleh 3 3,155 Aug-02-2020, 09:59 PM
Last Post: nilamo
  I can't control the speed of the turtle object Hesper 1 2,539 Apr-10-2020, 01:37 PM
Last Post: deanhystad
  open cv ->pygame: turn image into location Gamedeveloper 1 2,068 Jan-20-2020, 05:00 PM
Last Post: michael1789
  rect object not loading BlueClaw 2 4,153 Dec-11-2019, 04:25 PM
Last Post: BlueClaw
  beginner - object has no attribute gean 2 3,700 Nov-07-2019, 02:02 PM
Last Post: gean
  [pygame] Moving an object at angles SheeppOSU 3 8,575 Oct-24-2019, 08:05 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020