Lua smooth damp/tween algorithm [duplicate] - lua

This question already has an answer here:
Smooth damp or tween algorithm
(1 answer)
Closed 8 years ago.
I am trying to make an FPS but I need help on how to do smooth damp on my gun. It currently follows the mouse's position exactly but I want it to take a second to get there. Like a delay. I need this in Lua and can't use libraries.

Yes! Did some thinking and came up with an algorithm. Basically, I took mouse's current position and then made an if statement saying that if the position changes then it takes that number and divides it by 5

Related

How do I detect if a node has left the screen using SpriteKit [duplicate]

This question already has answers here:
How do you tell if a node is on the screen spritekit swift
(6 answers)
Closed 5 years ago.
I'm making a game, and I want to check if a node(the "player node") has left the screen.
There are 2 ways I thought of doing it:
Check the x and y coordinates, and see if they had exceeded those of the boundary, if they do, run gameOver().
Place a node just off screen, then if the player node comes in contact with that node, it runs gameOver().
I have no idea how I would do either of these so please . could someone help. Thanks!
Depends on the number of end points. If there are too many possible positions outside the screen, then check for the coordinates. If there are only a few, make sure they are nodes with a property noting for outside.

Gooey Effect in iOS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm working on a little project in which I would like two circles to connect through a gooey effect. I've searched the web quiet a lot and came across some examples in the form of a tabbar, or sidebar menu, but that's all fixed and not what I'm looking for.
What I basically want is the following. So there is a circle and if I drag it closely to another circle it snaps together, also known as the gooey effect.
A code sample would be the best, but a direction / approach of how to do this will help me out as well.
Interesting problem.
Off the top of my head, here is how I might handle it:
Calculate the points of intersection of the 2 circles (I found this link for that: Circle-circle intersection points)
Calculate the arc ranges of the intersecting parts of each circle.
Widen those arc ranges by a few degrees. Define the arcs for the remaining parts of each circle (The parts that would be drawn "non-gooey")
Using trig and Catmull-Rom splines, create a closed path for the outer "non-gooey" parts of each circle.
The Catmull-Rom algorithm should fill in the gaps between the 2 part-circles using smooth curves that look a lot like the "Gooey" circles you show.
I have a project on github that includes Swift code for creating Catmull-Rom splines from a series of points: Trochoid demo
That project creates open curves, not closed paths. The technique for creating smoothed closed paths using Catmull-Rom Splines is a little different. I have another Github project called RandomBlobs (Written in Objective-C) that creates smoothed closed paths. You should be able to work out how to change the Swift code to create closed paths from the Objective-C code. It's been long enough since I wrote the RandomBlobs code that I don't remember exactly what I did.
I'm not sure if the approach I describe above would be fast enough to draw in real time, but I bet it would. That TrochoidDemo project is doing a lot of trig for each animation frame, and it's animation is pretty smooth. If your project isn't smooth enough you might need to do some optimization.

Detect Bump On Bottom Of iPhone [duplicate]

This question already has answers here:
Detect when an iphone has been bumped
(5 answers)
Closed 6 years ago.
I have been doing a lot of research in the area of an iPhone's magnetometer, gyroscope and accelerometer, but can't seem to a good conclusion.
Things I have tried so far:
Acceleration in one direction to detect a stop. (Always detected when person is holding phone, and seems to just move in that direction)
Gyroscope angle changing directions regarding the way in which a person is holding the device. (Not consistent because trying to get shake to work with this as well)
Bump API/Existing Code (Does not work)
Has anyone come across a solid solution for detecting a tap on the bottom of and iPhone, against an object? Preferably with sample code.
Perhaps this is what you are looking for? It's a set of custom wrappers around the hardware that is designed specifically for detecting "accidents", which sounds like what you're looking for.

Need some tips which localization method to use for my NAO robot (robotic) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
for university I'm working on a project in which I have to teach a robot(Nao-robot) play nine men's morris. Unfortunately I'm fairly new to the area of robotics and I need some tips how to solve some problems. Currently I'm working on the localization/orientation of the robot and I'm wondering which approach of localization would fit best in my project.
A short explanation of the project:
The robot has a fixed starting position and has to walk around on a boardwhich has a size of about 3x3 meter ( I will post a picture of the board when i reach 10 reputation). There are no obstacles on the field except the game tokens and the game lines are marked yellow on the board. For orientation I use the two camera devices the robot has.
I found some approaches like
Monte Carlo Localization
SLAM (Simultaneous Localization and Mapping)
but these approaches seem to be quite complex for a beginner like me and I would really appreciate if some has some good ideas what would be a simpler way to solve this problem. Functionality has for me a far higher priority than performance.
I have vague knowledge about the nine men's morris game as such, but I will try to give you my simpler idea.
First thing first, you need to have a map of your board. This should be easy in your case, cause your environment is static. There are few technique to do this mapping from your board. For your case I would suggest to have a metric map, which is an occupancy grid. Assign coordinates to each cell in the grid. This will be helpful in robot navigation.
As you have mentioned, your robot starts from a fixed position. On start up, initialize your robot with this reference location and orientation (with respect to X-Y axes of the grid, may be you don't need the cameras, I am not sure!!). By initialization I mean, mark your position on the grid.
Use Dead Reckoning for localization and keep updating position and orientation of your robot as it move through the board. I would hope that your robot get some feedback from the servos, like number of rotations and so forth. Do that math and update the position coordinates of your robot as it move into different cell in the grid.
You can use A-Star algorithm to find a path for your robot. You need to do the path planning before you want to navigate. You also have to mark those game tokens on the grid, to avoid collisions in planning the path.

iOS fastest way to draw many rectangles [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to display audio meters on the iPad consisting of many small green, red or black rectangles. They don't need to be fancy but there may be a lot of them. I am looking for the best technique to draw them quickly. Which of the following techniques is better: text atlas in CALayers or OpenGLES or another?
Thank you for your answers before the the question was closed for being too broad. Unfortunately I couldn't make the question narrow because I didn't know which technology to use. If I had known the answer I could have made the question very narrow.
The fastest drawing would be to use OpenGLES in a custom view.
An alternative method would be to use a texture atlas in CALayers. You could draw 9 sets of your boxes into a single image to start with (0-8 boxes on), and then create the 300 CALayers on screen all using that as their content. During each frame, you switch each layer to point at the part of the texture atlas it needs to use. I've never done this with 300 layers before, so I don't know if that may become a problem - I've only done it with a half dozen or so digits that were updating every frame, but that worked really well. See this blog post for more info:
http://supermegaultragroovy.com/2012/11/19/pragma-mark-calayer-texture-atlases/
The best way to draw something repeatedly is to avoid drawing it if it is already on the screen. Since audio meters tend to update frequently, but most of their area stay the same, because audio signals are relatively smooth, you should track what's drawn, and draw only the differences.
For example, if you have drawn a signal meter with fifty green squares in a previous update, and now you need to draw forty eight green squares, you should redraw only the two squares that are different from the previous update. This should save you a lot of quartz calls.
Postpone rendering to the point where it's absolutely necessary, i. e. assuming you're drawing with CoreGraphics, use paths, and only stroke/fill the path when you have added all the rectangles to it.

Resources