physics

Game Physics - Not very life-like

柔情痞子 提交于 2019-12-12 04:59:11
问题 In a simple game (cocos2d) I have a made a small physics engine to move a sprite so that it can jump and stand on platforms ect. To update the position (vertical movement) I use basic kinematics equations in each update: position = oldPosition + velocity(delta) +1/2(gravity)(delta)^2 velocity = oldVelocity + (gravity)(delta) For some reason the game doesn't seem very life-like. It seems to take a long time near the top of an arc, despite how great I make gravity. If I want my sprite to jump

How to create ROOT histograms out of a 3 column .dat file?

久未见 提交于 2019-12-12 04:25:26
问题 I currently have a .dat file with format: Format: Log(10,s22th13) deltacp chi^2 -4 0 0.098127 -4 4 0.093642 -4 8 0.089323 -4 12 0.085185 -4 16 0.081242 .... How would I create a plot using ROOT, keeping the labels specified at the top of the .dat file? 回答1: The easiest way would be to read your file using TTree class: TTree *T = new TTree("ntuple","data from csv file"); Long64_t nlines = T->ReadFile("data.csv"); printf("found %lld points\n",nlines); Your header will be used as names for

SKSpriteKit maintaining constant velocity after collision

眉间皱痕 提交于 2019-12-12 03:50:44
问题 I am attempting to make my first iOS app and currently running into an issue. In my game, when the ball bounces I want it to bounce back to the same height and with the same velocity. Currently it does that just fine. However, when I rotate the hexagon and it hits an angle, it ends up losing speed and not bouncing to the same height. So my question is: How do I force the ball to maintain the same velocity upon collision? Here is the code for my Ball node: func createBallNode(ballColor: String

Integrating differential equations of motion for orbit in Runge Kutta in C

守給你的承諾、 提交于 2019-12-12 03:48:45
问题 I'm attempting to integrate the differential equations for planetary orbit using fourth order runge-kutta in C. The first equation that I attempted to integrate was for the position, dr/dt = sqrt((2/mu)*(E-(k/r)) - pow(l, 2)/(pow(mu, 2)*pow(r, 2))). The program compiles correctly but keeps on returning nan, I'm fairly new to C so I'm wondering why that could be. The source code that I'm using is the following: double rk4 ( double t0, double u0, double dt, double f ( double t, double u ) ) { /

How to rework acceleration formula for double pendulum with mouse interaction

别等时光非礼了梦想. 提交于 2019-12-12 01:13:13
问题 I need to make the mousePressed() function move the entire pendulum within the bounds of its length (r1 and r2 = 200). Lines 32-44 need to change based on the mousePressed function I have code for a single pendulum that uses PGraphics with a function that works the way i want it to. It uses the length of the pendulum as the maximum displacement for the ball at the end. I need to translate this into a double pendulum that accounts for two lengths instead of one.After running the program for a

How can I plot output from a function which returns multiple values in Python?

自古美人都是妖i 提交于 2019-12-11 20:38:25
问题 Short intro I'm calculating and plotting spectral energy of planets orbiting pulsar from given data. I have previously ordered all data in a list variations with dimensions [172, 2] (172 rows and 2 columns). Firstly, I have to calculate parameters of a presupposed model and spectral energy accordingly (from those very parameters). To do that, I defined a function under which I defined the presupposed model and find_fit function which takes the model and variations data. Code var('a, b, t')

Scrolling the 2d world with physics

坚强是说给别人听的谎言 提交于 2019-12-11 16:38:23
问题 I'm writing a side scrolling game with physics. Before get my hands dirty i started concentrating on physics and rendering graphics. Initially i thought of keeping every thing static (non scrolling). For physics after referring to many tutorial finally i ended up here http://www.tonypa.pri.ee/vectors/tut08.html. This set of tutorial covers most of the basic/advanced physics required for simple game. By following this tutorial i have created my 2d world with objects like triangle , box ,.....

Implementing Collision Detection

允我心安 提交于 2019-12-11 16:05:35
问题 I wrote a program that will simulate a ball being thrown off a 50 meter building. I added in collision detection by reversing the velocity in the y direction when the ball hits the ground (y < 0), keeping the horizontal velocity the same, and multiplying both velocities by some min value, so that the ball will ultimately come to a rest. #include<stdio.h> #include<math.h> #include <stdlib.h> int main() { FILE *fp; FILE *fr; float ax = 0, ay = 0, x = 0, y = 0, vx = 0, vy = 0; float time = 0,

chipmunk collision too soft

风格不统一 提交于 2019-12-11 13:16:14
问题 I'm new to physics in cocos2d. I'm using chipmunk, and when two object collide, its just to "soft", like they where made of sponge or rubber. My code: cpInitChipmunk(); space = cpSpaceNew(); space->gravity = cpv(0, 0); schedule(schedule_selector(HelloWorld::step), 1.0f/60.f); astroBody = cpBodyNew(100, INFINITY); astroBody->p = cpv(512,384); cpSpaceAddBody(space, astroBody); int num2 = 8; cpVect vertsAstro[] = { cpv(-17.0f, -44.9f), cpv(-29.5f, -33.2f), cpv(-32.9f, -13.1f), cpv(-24.0f, 11.7f)

how do you reflect a vector over another vector?

会有一股神秘感。 提交于 2019-12-11 11:42:56
问题 I'm using AS3 to program some collision detection for a flash game and am having trouble figuring out how to bounce a ball off of a line. I keep track of a vector that represents the ball's 2D velocity and I'm trying to reflect it over the vector that is perpendicular to the line that the ball's colliding with (aka the normal). My problem is that I don't know how to figure out the new vector (that's reflected over the normal). I figured that you can use Math.atan2 to find the difference