22

When I had this problem while working on my Cubes, I found the paper "A Fast Voxel Traversal Algorithm for Ray Tracing" by John Amanatides and Andrew Woo, 1987 which describes an algorithm which can be applied to this task; it is accurate and needs only one loop iteration per voxel intersected. I have written an implementation of the relevant parts of the ...


14

There is no reason to communicate over the network when the player selects units, because in most games just selecting a unit has no game-mechanical consequences. So this is an information which isn't relevant to the server or to the other players. But what would be important is when the player gives a command to one or more units. When issuing a move-...


8

There are a few tricks you can do: Z-buffer After you have rendered all other objects, for each unit render a transparent circle of smaller size with max Z value. Then render selection circles decals on the ground. Since they are below in Z-order, they will be discarded when under units. Being fully transparent means that the circle gets written only to Z-...


6

The way I do picking in core OpenGL is to assign a unique color to every object in the world and draw only the vertices (no texcoords, normals, etc.) with the assigned color to a FBO. Once all the objects have been drawn, you can call glReadPixels at the mouse coordinate with a width and height of 1 to get the pixel color at that point. Then all you have to ...


4

I'd warn against MVC for games in the first place, but putting said logic in the controller is fine. You can also put a small bit in the model if you want to be really pure. The Model contains a selection state and the Controller modifies this. Then the View uses this state to do its rendering. Something like: Model: bool selected = false Controller: ...


3

I managed to figure this out. You need to manually tell the EventSystem that the object has been selected. On a method such as OnPointerDown() you need to call the EventSystem.current.SetSelectedGameObject() method and pass in the event data and your gameobject. public class SelectableText : MonoBehaviour, IEventSystemHandler, ISelectHandler, ...


2

In modern OpenGL you shouldn't use GL_SELECT for objects picking since OpenGL is an API for hardware accelarated graphics drawing. But there are other methods which you can use. As @Robert wrote, you can use color selection in order to pick objects on the screen. Another thing you can do is to cast a ray from the mouse cursor to the game world and check for ...


2

For a rectangular selection, it would be a lot like your existing code. def mouseDown(self, button, pos): self.selection_rectangle_start = self.coord_convert(pos) def mouseMotion(self, pos): self.selection_rectangle_end = self.coord_convert(pos) self.selection_rectangle = calc_rect(self.selection_rectangle_start, self.selection_rectangle_end) ...


2

An actual VertexBuffer should really only be used for vertice information that wont be changing very often. When you assign a vertex array to a vertex buffer you are essentially moving the vertex info onto the gpu and receiving a reference to it that you can use to indicate to the GraphicsDevice that you will be using for the next render operation. If you ...


2

It sounds like you want to extend the Unity editor. Looks like you can use the Handles class to create custom handles for your objects too.


2

So, first of all, let's say you're trying to resize a cuboid (and it will stay a cuboid). The correct solution in this case isn't to modify vertices or even to use bones. What you want to do is use a model matrix that specifies a scale. You can then scale your model on each axis to place the vertices where you want them. But, let's say that you're sure that ...


2

Ran into the same situation myself recently and try as I might I never got the event to fire off. I'm guessing Selectable does some kind of initialization with the Event System, maybe adding the game object to a list of selectable objects or maybe checking the Input Position versus the graphic the control contains etc... But you can get around this simply ...


1

The step you are missing is the perspective divide. To calculate the value to divide by you have to do the perspective matrix math anyway so you might as well convert the point from world space into screen space and solve the problem in 2D screen coordinates. If you're curious about the math involved you can read up on how the perspective matrix works here


1

If I remember correctly, I iterate through all sprites and use their inverse affine matrix to convert the click coordinate into local space for the sprite. I then use a trivial bounding box check to determine if the local coord can be ruled out quickly as a hit for that sprite. If the bounding box check passes, I then perform an alpha test on the pixel of ...


1

I would solve this by creating click handler behaviors for everything which is clickable. But the primary purpose of that behavior would not be to actually act on the click event but rather find out what the users intention is, convert it into a command and then delegate the execution of that command to a central command handler. For example, the behavior I ...


1

This is a general overview of how to approach the problem. I haven't included any code, but hopefully it's enough to answer your question. A good way to approach this may be to use Physics.BoxCastAll(). BoxCast is similar to Raycast but, as the name suggests, uses a box instead of a ray. First, you will need some type of collider on your units that the ...


1

Problem solved! It is just a glitch. After you ctrl click and start cloning, the source mask stays on a single pixel.


1

You could take a look at how phaser debug works: https://github.com/photonstorm/phaser/blob/v2.4.2/src/physics/p2/BodyDebug.js On line 90 you have the 'draw' function that shows you how phaser draw the shapes. If you take a look at the last part of the function you can have a way to get the verts of the polygons of each shape: verts = []; vrot = p2.vec2....


1

I finally found out what I was doing wrong. I was retrieving the wrong start points for drawing the rectangle. When triggering the mousedown I had to get event.button.x instead of GetMouseState Here is the updated Mouse.h #ifndef MOUSE_H_ #define MOUSE_H_ class Mouse { public: bool leftButtonDown = false; bool mouseMoves = false; struct ...


1

One option is to take the screen coordinates for the rectangles corner points, convert them to rays in world space and then use these to define a box to do 3D collision detection with. The maximum length of the box should be the distance between the camera's near and far clipping plane.


1

For the width and height, you can just get the absolute value of the difference between the mouse and the start of the box. selectionBox.Width = Math.Abs(mouse.X - selectionBox.X); selectionBox.Height = Math.Abs(mouse.Y - selectionBox.Y); As for the X and Y, you'll need to maintain two values if you want them to always correspond to the top left. Something ...


1

Clicking should be handled in a separate layer. In the past, I've called this layer the HUD (heads up display), and it handles unit selection, giving commands to the selected units, moving the view port, and other user activities that are not part of "the game". So instead of having each unit check where the user has clicked, have your HUD handle each click ...


1

On touch devices, developers are freely given two seperate events in the form of "touch and hold" and "tap". You could try to implement this manually. Since you seem to want to use the same button for both actions, I think the best solution would be implementing some sort of miniscule delay between clicking a point, and them moving to it (say, 200ms). If the ...


1

Generally, you wouldn't do this. There are data structures designed for easy modification, such as those based on lists of half-edges. You would modify that data then regenerate the VertexBuffet rather than modifying the buffer directly. The basic idea is to find all vertices belonging to the face (again, much easier with a data structure designed for it) ...


1

A vertex buffer is just as it sounds, a big list of vertex data, and you can frequently access this data by simply indexing the buffer. Changing the values stored in the vertex buffer will achieve the results you want of moving the vertex to a new position. You will have to develop a system yourself for skinning verts to bones, or at least identifying the ...


1

I have to admit i am unfamiliar with python, but i think following steps seem appropriate: Once the mouse is pressed down store the position it is currently at. Start checking for a change in the mouse's position whenever the mouse is moved, or every X milliseconds. If the mouse position has changed before the mouse is released then store the new mouse ...


1

Perhaps look into Bresenham's line algorithm, particularly if you're working with unit-blocks (as most minecraftish games tend to). Basically this takes any two points, and traces an unbroken line between them. If you cast a vector from the player to their maximum picking distance, you can use this, and the players positions as points. I have a 3D ...


Only top voted, non community-wiki answers of a minimum length are eligible