Search Results

Search found 378 results on 16 pages for 'gravity'.

Page 1/16 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Platformer gravity where gravity is greater than tile size

    - by Sara
    I am making a simple grid-tile-based platformer with basic physics. I have 16px tiles, and after playing with gravity it seems that to get a nice quick Mario-like jump feel, the player ends up moving faster than 16px per second at the ground. The problem is that they clip through the first layer of tiles before collisions being detected. Then when I move the player to the top of the colliding tile, they move to the bottom-most tile. I have tried limiting their maximum velocity to be less than 16px but it does not look right. Are there any standard approaches to solving this? Thanks.

    Read the article

  • Increasing efficiency of N-Body gravity simulation

    - by Postman
    I'm making a space exploration type game, it will have many planets and other objects that will all have realistic gravity. I currently have a system in place that works, but if the number of planets goes above 70, the FPS decreases an practically exponential rates. I'm making it in C# and XNA. My guess is that I should be able to do gravity calculations between 100 objects without this kind of strain, so clearly my method is not as efficient as it should be. I have two files, Gravity.cs and EntityEngine.cs. Gravity manages JUST the gravity calculations, EntityEngine creates an instance of Gravity and runs it, along with other entity related methods. EntityEngine.cs public void Update() { foreach (KeyValuePair<string, Entity> e in Entities) { e.Value.Update(); } gravity.Update(); } (Only relevant piece of code from EntityEngine, self explanatory. When an instance of Gravity is made in entityEngine, it passes itself (this) into it, so that gravity can have access to entityEngine.Entities (a dictionary of all planet objects)) Gravity.cs namespace ExplorationEngine { public class Gravity { private EntityEngine entityEngine; private Vector2 Force; private Vector2 VecForce; private float distance; private float mult; public Gravity(EntityEngine e) { entityEngine = e; } public void Update() { //First loop foreach (KeyValuePair<string, Entity> e in entityEngine.Entities) { //Reset the force vector Force = new Vector2(); //Second loop foreach (KeyValuePair<string, Entity> e2 in entityEngine.Entities) { //Make sure the second value is not the current value from the first loop if (e2.Value != e.Value ) { //Find the distance between the two objects. Because Fg = G * ((M1 * M2) / r^2), using Vector2.Distance() and then squaring it //is pointless and inefficient because distance uses a sqrt, squaring the result simple cancels that sqrt. distance = Vector2.DistanceSquared(e2.Value.Position, e.Value.Position); //This makes sure that two planets do not attract eachother if they are touching, completely unnecessary when I add collision, //For now it just makes it so that the planets are not glitchy, performance is not significantly improved by removing this IF if (Math.Sqrt(distance) > (e.Value.Texture.Width / 2 + e2.Value.Texture.Width / 2)) { //Calculate the magnitude of Fg (I'm using my own gravitational constant (G) for the sake of time (I know it's 1 at the moment, but I've been changing it) mult = 1.0f * ((e.Value.Mass * e2.Value.Mass) / distance); //Calculate the direction of the force, simply subtracting the positions and normalizing works, this fixes diagonal vectors //from having a larger value, and basically makes VecForce a direction. VecForce = e2.Value.Position - e.Value.Position; VecForce.Normalize(); //Add the vector for each planet in the second loop to a force var. Force = Vector2.Add(Force, VecForce * mult); //I have tried Force += VecForce * mult, and have not noticed much of an increase in speed. } } } //Add that force to the first loop's planet's position (later on I'll instead add to acceleration, to account for inertia) e.Value.Position += Force; } } } } I have used various tips (about gravity optimizing, not threading) from THIS question (that I made yesterday). I've made this gravity method (Gravity.Update) as efficient as I know how to make it. This O(N^2) algorithm still seems to be eating up all of my CPU power though. Here is a LINK (google drive, go to File download, keep .Exe with the content folder, you will need XNA Framework 4.0 Redist. if you don't already have it) to the current version of my game. Left click makes a planet, right click removes the last planet. Mouse moves the camera, scroll wheel zooms in and out. Watch the FPS and Planet Count to see what I mean about performance issues past 70 planets. (ALL 70 planets must be moving, I've had 100 stationary planets and only 5 or so moving ones while still having 300 fps, the issue arises when 70+ are moving around) After 70 planets are made, performance tanks exponentially. With < 70 planets, I get 330 fps (I have it capped at 300). At 90 planets, the FPS is about 2, more than that and it sticks around at 0 FPS. Strangely enough, when all planets are stationary, the FPS climbs back up to around 300, but as soon as something moves, it goes right back down to what it was, I have no systems in place to make this happen, it just does. I considered multithreading, but that previous question I asked taught me a thing or two, and I see now that that's not a viable option. I've also thought maybe I could do the calculations on my GPU instead, though I don't think it should be necessary. I also do not know how to do this, it is not a simple concept and I want to avoid it unless someone knows a really noob friendly simple way to do it that will work for an n-body gravity calculation. (I have an NVidia gtx 660) Lastly I've considered using a quadtree type system. (Barnes Hut simulation) I've been told (in the previous question) that this is a good method that is commonly used, and it seems logical and straightforward, however the implementation is way over my head and I haven't found a good tutorial for C# yet that explains it in a way I can understand, or uses code I can eventually figure out. So my question is this: How can I make my gravity method more efficient, allowing me to use more than 100 objects (I can render 1000 planets with constant 300+ FPS without gravity calculations), and if I can't do much to improve performance (including some kind of quadtree system), could I use my GPU to do the calculations?

    Read the article

  • Multithreading 2D gravity calculations

    - by Postman
    I'm building a space exploration game and I've currently started working on gravity ( In C# with XNA). The gravity still needs tweaking, but before I can do that, I need to address some performance issues with my physics calculations. This is using 100 objects, normally rendering 1000 of them with no physics calculations gets well over 300 FPS (which is my FPS cap), but any more than 10 or so objects brings the game (and the single thread it runs on) to its knees when doing physics calculations. I checked my thread usage and the first thread was killing itself from all the work, so I figured I just needed to do the physics calculation on another thread. However when I try to run the Gravity.cs class's Update method on another thread, even if Gravity's Update method has nothing in it, the game is still down to 2 FPS. Gravity.cs public void Update() { foreach (KeyValuePair<string, Entity> e in entityEngine.Entities) { Vector2 Force = new Vector2(); foreach (KeyValuePair<string, Entity> e2 in entityEngine.Entities) { if (e2.Key != e.Key) { float distance = Vector2.Distance(entityEngine.Entities[e.Key].Position, entityEngine.Entities[e2.Key].Position); if (distance > (entityEngine.Entities[e.Key].Texture.Width / 2 + entityEngine.Entities[e2.Key].Texture.Width / 2)) { double angle = Math.Atan2(entityEngine.Entities[e2.Key].Position.Y - entityEngine.Entities[e.Key].Position.Y, entityEngine.Entities[e2.Key].Position.X - entityEngine.Entities[e.Key].Position.X); float mult = 0.1f * (entityEngine.Entities[e.Key].Mass * entityEngine.Entities[e2.Key].Mass) / distance * distance; Vector2 VecForce = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); VecForce.Normalize(); Force = Vector2.Add(Force, VecForce * mult); } } } entityEngine.Entities[e.Key].Position += Force; } } Yeah, I know. It's a nested foreach loop, but I don't know how else to do the gravity calculation, and this seems to work, it's just so intensive that it needs its own thread. (Even if someone knows a super efficient way to do these calculations, I'd still like to know how I COULD do it on multiple threads instead) EntityEngine.cs (manages an instance of Gravity.cs) public class EntityEngine { public Dictionary<string, Entity> Entities = new Dictionary<string, Entity>(); public Gravity gravity; private Thread T; public EntityEngine() { gravity = new Gravity(this); } public void Update() { foreach (KeyValuePair<string, Entity> e in Entities) { Entities[e.Key].Update(); } T = new Thread(new ThreadStart(gravity.Update)); T.IsBackground = true; T.Start(); } } EntityEngine is created in Game1.cs, and its Update() method is called within Game1.cs. I need my physics calculation in Gravity.cs to run every time the game updates, in a separate thread so that the calculation doesn't slow the game down to horribly low (0-2) FPS. How would I go about making this threading work? (any suggestions for an improved Planetary Gravity system are welcome if anyone has them) I'm also not looking for a lesson in why I shouldn't use threading or the dangers of using it incorrectly, I'm looking for a straight answer on how to do it. I've already spent an hour googling this very question with little results that I understood or were helpful. I don't mean to come off rude, but it always seems hard as a programming noob to get a straight meaningful answer, I usually rather get an answer so complex I'd easily be able to solve my issue if I understood it, or someone saying why I shouldn't do what I want to do and offering no alternatives (that are helpful). Thank you for the help!

    Read the article

  • Jump handling and gravity

    - by sprawl
    I'm new to game development and am looking for some help on improving my jump handling for a simple side scrolling game I've made. I would like to make the jump last longer if the key is held down for the full length of the jump, otherwise if the key is tapped, make the jump not as long. Currently, how I'm handling the jumping is the following: Player.prototype.jump = function () { // Player pressed jump key if (this.isJumping === true) { // Set sprite to jump state this.settings.slice = 250; if (this.isFalling === true) { // Player let go of jump key, increase rate of fall this.settings.y -= this.velocity; this.velocity -= this.settings.gravity * 2; } else { // Player is holding down jump key this.settings.y -= this.velocity; this.velocity -= this.settings.gravity; } } if (this.settings.y >= 240) { // Player is on the ground this.isJumping = false; this.isFalling = false; this.velocity = this.settings.maxVelocity; this.settings.y = 240; } } I'm setting isJumping on keydown and isFalling on keyup. While it works okay for simple use, I'm looking for a better way handle jumping and gravity. It's a bit buggy if the gravity is increased (which is why I had to put the last y setting in the last if condition in there) on keyup, so I'd like to know a better way to do it. Where are some resources I could look at that would help me better understand how to handle jumping and gravity? What's a better approach to handling this? Like I said, I'm new to game development so I could be doing it completely wrong. Any help would be appreciated.

    Read the article

  • Gravity Sort : Is this possible programatically?

    - by Bragaadeesh
    Hi, I've been thinking recently on using the Object Oriented design in the sorting algorithm. However I was not able to find a proper way to even come closer in making this sorting algorithm that does the sorting in O(n) time. Ok, here is what I've been thinking for a week. I have a set of input data. I will assign a mass to each of the input data (assume input data a type of Mass). I will be placing all my input data in the space all at same distance from earth. And I will make them free fall. According to gravitational law, the heaviest one hits the ground first. And the order in which they hit will give me the sorted data. This is funny in some way, but underneath I feel that this should be possible using the OO that I have learnt till date Is it really possible to make a sorting technique that uses gravitational pull like scenario or am I stupid/crazy?

    Read the article

  • 2D Planet Gravity

    - by baked
    I'm trying to make a simple game where a spaceship is launched and then its path is effected by the gravity of planets. Similar to this game: http://sciencenetlinks.com/interactives/gravity.html I wish to know how to replicate the effect the planets have on the spaceship in this game so a spaceship can 'loop' around a planet to change direction. I have managed to achieve some bogus results where the spaceship loops in a huge ellipse around the planet or is only slightly affected by the gravity of a planet using Vectors. Thanks in advance. p.s I have plenty of coding experience just none to do with game dev.

    Read the article

  • Remove gravity from single body

    - by Siddharth
    I have multiple bodies in my game world in andengine. All the bodies affected by gravity but in that I want my specific body does not affected by the gravity. For that solution after research I found that I have to use body.setGravityScale(0) method for my problem solution. But in my andengine extension I don't found that method so please provide guidance about how get access about that method. Also for the above problem any other guidance will be acceptable. Thank You! I apply following code for reverse gravity final Vector2 vec = new Vector2(0, -SensorManager.GRAVITY_EARTH * bulletBody.getMass()); bulletBody.applyForce(vec, bulletBody.getWorldCenter());

    Read the article

  • Gravity stops when side-collision detected

    - by Adrian Marszalek
    Please, look at this GIF: The label on the animation says "Move button is pressed, then released". And you can see when it's pressed (and player's getCenterY() is above wall getCenterY()), gravity doesn't work. I'm trying to fix it since yesterday, but I can't. All methods are called from game loop. public void move() { if (left) { switch (game.currentLevel()) { case 1: for (int i = 0; i < game.lvl1.getX().length; i++) game.lvl1.getX()[i] += game.physic.xVel; break; } } else if (right) { switch (game.currentLevel()) { case 1: for (int i = 0; i < game.lvl1.getX().length; i++) game.lvl1.getX()[i] -= game.physic.xVel; break; } } } int manCenterX, manCenterY, boxCenterX, boxCenterY; //gravity stop public void checkCollision() { for (int i = 0; i < game.lvl1.getX().length; i++) { manCenterX = (int) game.man.getBounds().getCenterX(); manCenterY = (int) game.man.getBounds().getCenterY(); if (game.man.getBounds().intersects(game.lvl1.getBounds(i))) { boxCenterX = (int) game.lvl1.getBounds(i).getCenterX(); boxCenterY = (int) game.lvl1.getBounds(i).getCenterY(); if (manCenterY - boxCenterY > 0 || manCenterY - boxCenterY < 0) { game.man.setyPos(-2f); game.man.isFalling = false; } } } } //left side of walls public void colliLeft() { for (int i = 0; i < game.lvl1.getX().length; i++) { if (game.man.getBounds().intersects(game.lvl1.getBounds(i))) { if (manCenterX - boxCenterX < 0) { for (int i1 = 0; i1 < game.lvl1.getX().length; i1++) { game.lvl1.getX()[i1] += game.physic.xVel; game.man.isFalling = true; } } } } } //right side of walls public void colliRight() { for (int i = 0; i < game.lvl1.getX().length; i++) { if (game.man.getBounds().intersects(game.lvl1.getBounds(i))) { if (manCenterX - boxCenterX > 0) { for (int i1 = 0; i1 < game.lvl1.getX().length; i1++) { game.lvl1.getX()[i1] += -game.physic.xVel; game.man.isFalling = true; } } } } } public void gravity() { game.man.setyPos(yVel); } //not called from gameloop: public void setyPos(float yPos) { this.yPos += yPos; }

    Read the article

  • How to do the Geometry Wars gravity well effect

    - by Mykel Stone
    I'm not talking about the background grid here, I'm talking about the swirly particles going around the Gravity Wells! I've always liked the effect and decided it'd be a fun experiment to replicate it, I know GW uses Hooke's law all over the place, but I don't think the Particle-to-Well effect is done using springs, it looks like a distance-squared function. Here is a video demonstrating the effect: http://www.youtube.com/watch?v=YgJe0YI18Fg I can implement a spring or gravity effect on some particles just fine, that's easy. But I can't seem to get the effect to look similar to GWs effect. When I watch the effect in game it seems that the particles are emitted in bunches from the Well itself, they spiral outward around the center of the well, and eventually get flung outward, fall back towards the well, and repeat. How does he make the particles spiral outward when spawned? How does he keep the particle bunches together when near the Well but spread away from each other when they're flung outward? How does he keep the particles so strongly attached to the Well?

    Read the article

  • Game Maker Studio Gravity Problems

    - by Dusty
    I've started messing around with Game Maker Studio. The problem I'm having is trying to get a gravity code for orbiting. Here's how i did it in XNA foreach (GravItem Item in StarSystem.ActiveItems.OfType<GravItem>()) { if (this != Item) { Velocity += (10 * Vector2.Normalize(Item.Position - this.Position * (this.Mass * Item.Mass) / (Vector2.DistanceSquared(this.Position, Item.Position)) / (this.Mass)); } } Simple and works well, things or bit and everything is nice. but in Game maker i don't have the luxury of Vector2's or a For-each loop to loop threw all the objects that have a mass. I've tried a few different things but nothing seems to work distance = distance_to_object(obj_moon); //--Gravity hspeed += (0.5 * (distance) * (Mass * obj_moon.Mass) / (sqr(distance)) / Mass) vspeed += (0.5 * (distance) * (Mass * obj_moon.Mass) / (sqr(distance)) / Mass) thanks for the help

    Read the article

  • Gravity Forms not loading under https, jQuery is not defined

    - by cmykrgbb
    I am using Gravity Forms on my Wordpress site, and so far so good. The problem is I have made the page secure (https/SSL), and this is making the form not to work. It looks like the issue is how the site is trying to load jQuery. There are 23 JS errors on the page, which seem to be due to a failed jQuery load "Uncaught ReferenceError: jQuery is not defined". If I go to the page where the source is trying to pull the jQuery file, you'll see the error:https://code.jquery.com/jquery-1.7.1.min.js?ver=3.4.2 Screenshot of the error: https://www.evernote.com/shard/s212/sh/326f95d6-a498-4c33-b413-7e968225cc79/c2e380ed0fa02a913f712005c8301185 And this screenshot is the reference in the page source: https://www.evernote.com/shard/s212/sh/ae547962-c017-4321-90a2-c51433e59262/124ae116f2b803771f4eb36c90b5a524 So I have been told I'd want to look into that - that's where the ultimate issue is, but I don't really know what to do next. Is it failing because of Gravity Forms, the HTTPS plugin from Wordpress, my SSL certificate...? Thanks in advance!

    Read the article

  • Jumping Vs. Gravity

    - by PhaDaPhunk
    Hi i'm working on my first XNA 2D game and I have a little problem. If I jump, my sprite jumps but does not fall down. And I also have another problem, the user can hold spacebar to jump as high as he wants and I don't know how to keep him from doing that. Here's my code: The Jump : if (FaKeyboard.IsKeyDown(Keys.Space)) { Jumping = true; xPosition -= new Vector2(0, 5); } if (xPosition.Y >= 10) { Jumping = false; Grounded = false; } The really simple basic Gravity: if (!Grounded && !Jumping) { xPosition += new Vector2(1, 3) * speed; } Here's where's the grounded is set to True or False with a Collision Rectangle MegamanRectangle = new Rectangle((int)xPosition.X, (int)xPosition.Y, FrameSizeDraw.X, FrameSizeDraw.Y); Rectangle Block1Rectangle = new Rectangle((int)0, (int)73, Block1.Width, Block1.Height); Rectangle Block2Rectangle = new Rectangle((int)500, (int)73, Block2.Width, Block2.Height); if ((MegamanRectangle.Intersects(Block1Rectangle) || (MegamanRectangle.Intersects(Block2Rectangle)))) { Grounded = true; } else { Grounded = false; } The grounded bool and The gravity have been tested and are working. Any ideas why? Thanks in advance and don't hesitate to ask if you need another Part of the Code.

    Read the article

  • Collision detection, stop gravity

    - by Scott Beeson
    I just started using Gamemaker Studio and so far it seems fairly intuitive. However, I set a room to "Room is Physics World" and set gravity to 10. I then enabled physics on my player object and created a block object to match a platform on my background sprite. I set up a Collision Detection event for the player and the block objects that sets the gravity to 0 (and even sets the vspeed to 0). I also put a notification in the collision event and I don't get that either. I have my key down and key up events working well, moving the player left and right and changing the sprites appropriately, so I think I understand the event system. I must just be missing something simple with the physics. I've tried making both and neither of the objects "solid". Pretty frustrating since it looks so easy. The player starting point is directly above the block object in the grid and the player does fall through the block. I even made the block sprite solid red so I could see it (initially it was invisible, obviously).

    Read the article

  • Unity3d Gravity script issues

    - by Joseph Le Brech
    I'm try this script out http://wiki.unity3d.com/index.php/Gravity and I'm having some issues with it (it seemed to work when I tried it with an old version of unity) the first issue is of collision, the objects (in my case spheres) will stick into each other rather than just touch. and the second is that when the objects collide one of the objects with continue it's trajectory. I'm thinking of rewriting the script from scratch unless someone can explain what's wrong with the script that i've got.

    Read the article

  • Accelerometer gravity components

    - by Dvd
    Hi, I know this question is definitely solved somewhere many times already, please enlighten me if you know of their existence, thanks. Quick rundown: I want to compute from a 3 axis accelerometer the gravity component on each of these 3 axes. I have used 2 axes free body diagrams to work out the accelerometer's gravity component in the world X-Z, Y-Z and X-Y axes. But the solution seems slightly off, it's acceptable for extreme cases when only 1 accelerometer axis is exposed to gravity, but for a pitch and roll of both 45 degrees, the combined total magnitude is greater than gravity (obtained by Xa^2+Ya^2+Za^2=g^2; Xa, Ya and Za are accelerometer readings in its X, Y and Z axis). More detail: The device is a Nexus One, and have a magnetic field sensor for azimuth, pitch and roll in addition to the 3-axis accelerometer. In the world's axis (with Z in the same direction as gravity, and either X or Y points to the north pole, don't think this matters much?), I assumed my device has a pitch (P) on the Y-Z axis, and a roll (R) on the X-Z axis. With that I used simple trig to get: Sin(R)=Ax/Gxz Cos(R)=Az/Gxz Tan(R)=Ax/Az There is another set for pitch, P. Now I defined gravity to have 3 components in the world's axis, a Gxz that is measurable only in the X-Z axis, a Gyz for Y-Z, and a Gxy for X-Y axis. Gxz^2+Gyz^2+Gxy^2=2*G^2 the 2G is because gravity is effectively included twice in this definition. Oh and the X-Y axis produce something more exotic... I'll explain if required later. From these equations I obtained a formula for Az, and removed the tan operations because I don't know how to handle tan90 calculations (it's infinity?). So my question is, anyone know whether I did this right/wrong or able to point me to the right direction? Thanks! Dvd

    Read the article

  • Strange behavior of RigidBody with gravity and impulse applied

    - by Heisenbug
    I'm doing some experiments trying to figure out how physics works in Unity. I created a cube mesh with a BoxCollider and a RigidBody. The cuve is laying on a mesh plane with a BoxCollider. I'm trying to update the object position applying a force on its RigidBody. Inside script FixedUpdate function I'm doing the following: public void FixedUpdate() { if (leftButtonPressed()) this.rigidbody.AddForce( this.transform.forward * this.forceStrength, ForceMode.Impulse); } Despite the object is aligned with the world axis and the force is applied along Z axis, it performs a quite big rotation movement around its y axis. Since I didn't modify the center of mass and the BoxCollider position and dimension, all values should be fine. Removing gravity and letting the object flying without touching the plane, the problem doesn't show. So I suppose it's related to the friction between objects, but I can't understand exactly which is the problem. Why this? What's my mistake? How can I fix this, or what's the right way to do such a moving an object on a plane through a force impulse?

    Read the article

  • Is there an example for mark with right gravit?

    - by Runner
    Quoted from here: The standard left-to-right cursor is a mark with right gravity (when you type, the cursor stays on the right side of the text you're typing). Now I see what's an mark with right gravity. But I still don't have an idea what's a mark with left gravity like,is there an example of left gravity mark?

    Read the article

  • iPhone OpenGL ES: How do I use gravity vector to correctly transform scene for augmented reality

    - by gpdawson
    I'm trying figure out how to get an OpenGL specified object to be displayed correctly according to the device orientation (ie. according to the gravity vector from the accelerometer, and heading from compass). The GLGravity sample project has an example which is almost like this (despite ignoring heading), but it has some glitches. For example, the teapot jumps 180deg as the device viewing angle crosses the horizon, and it also rotates spuriously if you tilt the device from portrait into landscape. This is fine for the context of this app, as it just shows off an object and it doesn't matter that it does these things. But it means that the code just doesn't work when you attempt to emulate real life viewing of an OpenGL object according to the device's orientation. What happens is that it almost works, but the heading rotation you apply from the compass gets "corrupted" by the spurious additional rotations seen in the GLGravity example project. Can anyone provide sample code that shows how to adjust correctly for the device orientation (ie. gravity vector), or to fix the GLGravity example so that it doesn't include spurious heading changes? //Clear matrix to be used to rotate from the current referential to one based on the gravity vector bzero(matrix, sizeof(matrix)); matrix[3][3] = 1.0; //Setup first matrix column as gravity vector matrix[0][0] = accel[0] / length; matrix[0][1] = accel[1] / length; matrix[0][2] = accel[2] / length; //Setup second matrix column as an arbitrary vector in the plane perpendicular to the gravity vector {Gx, Gy, Gz} defined by by the equation "Gx * x + Gy * y + Gz * z = 0" in which we arbitrarily set x=0 and y=1 matrix[1][0] = 0.0; matrix[1][1] = 1.0; matrix[1][2] = -accel[1] / accel[2]; length = sqrtf(matrix[1][0] * matrix[1][0] + matrix[1][1] * matrix[1][1] + matrix[1][2] * matrix[1][2]); matrix[1][0] /= length; matrix[1][1] /= length; matrix[1][2] /= length; //Setup third matrix column as the cross product of the first two matrix[2][0] = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1]; matrix[2][1] = matrix[1][0] * matrix[0][2] - matrix[1][2] * matrix[0][0]; matrix[2][2] = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]; //Finally load matrix glMultMatrixf((GLfloat*)matrix);

    Read the article

  • hint and textview with right gravity and a singleline

    - by codeScriber
    I've opened a bug but i was wondering if anyone encountered this issue and knows a workaround. If you define a text view with a hint inside it, give it right gravity (android:gravity="right") then if you define android:singleLine=true or android:maxLines="1" or android:scrollHorizonatally="true" you don't see the hint. removing the right gravity returns the hint to the left side, removing all the tree params i mentioned above puts the hint on the right side. i want my hint on the right, but i need a single horizontal line... here's the sample layout that doesn't show the hint: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp"> <EditText android:layout_width="fill_parent" android:layout_gravity="center_vertical|right" android:layout_height="wrap_content" android:layout_margin="6dp" android:textSize="16sp" android:paddingRight="5dp" android:id="@+id/c" android:gravity="right" android:hint="hello!!!" android:scrollHorizontally="true" android:maxLines="1" android:singleLine="true"/> </LinearLayout> i checked on 1.6 and 2.1 emulators and it reproduces 100%, i'm prettysure it's a bug, i don't see the connection between single line and the hint.... what's more the hint got it's own layout in the TextView (mLayout and mHintLayout both exists, in onDraw if the text length is 0 mHintLayout if mHint is not null is used).

    Read the article

  • 2D platformer gravity physics with slow-motion

    - by DD
    Hi all, I fine tuned my 2d platformer physics and when I added slow-motion I realized that it is messed up. The problem I have is that for some reason the physics still depends on framerate. So when I scale down time elapsed, every force is scaled down as well. So the jump force is scaled down, meaning in slow-motion, character jumps vertically smaller height and gravity force is scaled down as well so the character goes further in the air without falling. I'm sending update function in hopes that someone can help me out here (I separated vertical (jump, gravity) and walking (arbitrary walking direction on a platform - platforms can be of any angle) vectors): characterUpdate:(float)dt { //Compute walking velocity walkingAcceleration = direction of platform * walking acceleration constant * dt; initialWalkingVelocity = walkingVelocity; if( isWalking ) { if( !isJumping ) walkingVelocity = walkingVelocity + walkingAcceleration; else walkingVelocity = walkingVelocity + Vector( walking acceleration constant * dt, 0 ); } // Compute jump/fall velocity if( !isOnPlatform ) { initialVerticalVelocity = verticalVelocity; verticalVelocity = verticalVelocity + verticalAcceleration * dt; } // Add walking velocity position = position + ( walkingVelocity + initialWalkingVelocity ) * 0.5 * dt; //Add jump/fall velocity if not on a platform if( !isOnPlatform ) position = position + ( verticalVelocity + initialVerticalVelocity ) * 0.5 * dt; verticalAcceleration.y = Gravity * dt; }

    Read the article

  • Can't get gravity to work with RMagick and 'caption'

    - by mph
    I'm using RMagick 2.12.2 with ImageMagick 6.5.6-10 on Snow Leopard. I'm trying to put captions on a collection of photos, and I'm getting the caption to work (i.e. it appears on the image), but I can't get the gravity parameter to work correctly. No matter what I set it to, I end up with some variation on NorthGravity. For instance: Setting it to SouthWestGravity gives me NorthWestGravity. Setting it to SouthEastGravity gives me NorthEastGravity. Setting it to CenterGravity gives me NorthGravity. In other words, I can't get the caption to come down off the top of the image. I'd consider using "annotate," but I need "caption" so the lengthy caption text for each image will wrap. What am I doing wrong? Here's the code: #!/usr/bin/env ruby require "rubygems" require "yaml" require "RMagick" include Magick base_dir = "/Users/mike/Desktop/caption_test" photo_log = File.open("#{base_dir}/photo_log.yaml" ) YAML::load_documents(photo_log) do |doc| caption = doc["photo-caption"] filename = doc["file"] canvas = ImageList.new.from_blob(open("#{base_dir}/#{filename}") { |f| f.read } ) canvas << Magick::Image.read("caption:#{caption}") { self.gravity = SouthWestGravity self.size = "#{canvas.first.columns}" self.font = "Helvetica Neue" self.pointsize = 12 self.background_color = "#fff" }.first canvas.flatten_images.write("#{base_dir}/images/#{filename}") end

    Read the article

  • Win 7 Home Premium 64 bit running Cobian Backup 11 (Gravity)

    - by Andrew
    I'm really enjoying Cobian 11, but am fairly new to it. My question is this. I back up a pretty large folder on a regular basis. I started off by doing a Full backup, and have followed that monthly using differential backups. I was told that, to restore my computer after a crash, I need to copy back the original full backup AND copy back the latest differential over the full. That's fine. However, over the months there are quite a few large differential backups dated between the original Full one and the latest differential one. To free space on my backup HD, can I every now and then delete the differential backups that lie between the original Full and the latest differential, and just leave the original Full and the latest differential backup on the HD?

    Read the article

  • How can I create a weekly calendar view for an Android Honeycomb application?

    - by BVB
    I am working on an Android (v3.0) application that has a requirement of mimicking the weekly calendar layout found on Google Calendar: The events will be based on external requests through the Google Calendar API (I already have this part working). Using the API, I can obtain a list of events for the week, with each event having a starting and and ending datetime. I would like to use this data to show the scheduled events to the application's users in a view similar to the one above. Here's what I have so far: The XML appears below: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="800dp" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Calendar Title" android:textAppearance="?android:attr/textAppearanceLarge" /> <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" > <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> <TextView android:id="@+id/textView3" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Sunday" /> <TextView android:id="@+id/textView4" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Monday" /> <TextView android:id="@+id/textView5" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Tuesday" /> <TextView android:id="@+id/textView6" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Wednesday" /> <TextView android:id="@+id/textView7" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Thursday" /> <TextView android:id="@+id/textView8" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Friday" /> <TextView android:id="@+id/textView9" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="center" android:text="Saturday" /> </LinearLayout> </RelativeLayout> <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="0dp" android:scrollbars="none" >" <RelativeLayout android:id="@+id/relativeLayout242" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="0dp" > <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="0dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="40dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="80dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="120dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="160dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="200dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="240dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="280dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="320dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="360dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="400dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="440dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="480dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="520dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="560dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="600dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="640dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="680dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="720dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="760dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="800dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="840dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="880dp"/> <View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="920dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="20dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="60dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="100dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="140dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="180dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="220dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="260dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="300dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="340dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="380dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="420dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="460dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="500dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="540dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="580dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="620dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="660dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="700dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="740dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="780dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="820dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="860dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="900dp"/> <View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="940dp"/> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="0dp" > <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:padding="0dp" > <View android:background="#aaa" android:layout_width = "1dp" android:layout_height="fill_parent" android:layout_alignParentRight="true"/> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="0dp" android:gravity="center" android:text="12am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp" android:gravity="center" android:text="1am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="80dp" android:gravity="center" android:text="2am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="120dp" android:gravity="center" android:text="3am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="160dp" android:gravity="center" android:text="4am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="200dp" android:gravity="center" android:text="5am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="240dp" android:gravity="center" android:text="6am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="280dp" android:gravity="center" android:text="7am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="320dp" android:gravity="center" android:text="8am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="360dp" android:gravity="center" android:text="9am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="400dp" android:gravity="center" android:text="10am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="440dp" android:gravity="center" android:text="11am" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="480dp" android:gravity="center" android:text="12pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="520dp" android:gravity="center" android:text="1pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="560dp" android:gravity="center" android:text="2pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="600dp" android:gravity="center" android:text="3pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="640dp" android:gravity="center" android:text="4pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="680dp" android:gravity="center" android:text="5pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="720dp" android:gravity="center" android:text="6pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="760dp" android:gravity="center" android:text="7pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="800dp" android:gravity="center" android:text="8pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="840dp" android:gravity="center" android:text="9pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="880dp" android:gravity="center" android:text="10pm" /> <TextView android:id="@+id/textView10" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginTop="920dp" android:gravity="center|top" android:text="11pm" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="14" android:padding="0dp" > <LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:padding="0dp" > <RelativeLayout android:id="@+id/relativeLayout4" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="180dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_marginTop="180dp" android:text="Some Event" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout5" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="280dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_marginTop="280dp" android:text="Some Event" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout6" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="60dp" android:layout_marginTop="40dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_marginTop="40dp" android:text="Some Event" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout7" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="90dp" android:layout_marginTop="60dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="90dp" android:layout_marginTop="60dp" android:text="Some Event" /> <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="120dp" android:layout_marginTop="340dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="120dp" android:layout_marginTop="340dp" android:text="Some Event" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout8" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="380dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_marginTop="380dp" android:text="Some Event" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout9" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="480dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_marginTop="480dp" android:text="Some Event" /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeLayout10" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="340dp"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_marginTop="340dp" android:text="Some Event" /> </RelativeLayout> </LinearLayout> </RelativeLayout> </LinearLayout> </RelativeLayout> </ScrollView> </LinearLayout> My approach was to make 40dp equal to 1 hr of time. Thus, whenever I would like to add an event that has a duration of 1.5 hours, I will make an 60dp button that I will place at the exact location that the time begins (12am = 0dp from the top, 1pm = 40dp from the top, 2pm = 80d from the top, etc). My questions are: Is there a better way of doing this? How can I convert my XML to be stand-alone view that could be added to any Android project? (I plan on perhaps making a blog post about the end product) Thank you!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >