Search Results

Search found 4022 results on 161 pages for 'float dublin'.

Page 18/161 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Android Can't get two virtual joysticks to move independently and at the same time

    - by Cole
    @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub float r = 70; float centerLx = (float) (screenWidth*.3425); float centerLy = (float) (screenHeight*.4958); float centerRx = (float) (screenWidth*.6538); float centerRy = (float) (screenHeight*.4917); float dx = 0; float dy = 0; float theta; float c; int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; int pid = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; int fingerid = event.getPointerId(pid); int x = (int) event.getX(pid); int y = (int) event.getY(pid); c = FloatMath.sqrt(dx*dx + dy*dy); theta = (float) Math.atan(Math.abs(dy/dx)); switch (actionCode) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: //if touching down on left stick, set leftstick ID to this fingerid. if(x < screenWidth/2 && c<r*.8) { lsId = fingerid; dx = x-centerLx; dy = y-centerLy; touchingLs = true; } else if(x > screenWidth/2 && c<r*.8) { rsId = fingerid; dx = x-centerRx; dy = y-centerRy; touchingRs = true; } break; case MotionEvent.ACTION_MOVE: if (touchingLs && fingerid == lsId) { dx = x - centerLx; dy = y - centerLy; }else if (touchingRs && fingerid == rsId) { dx = x - centerRx; dy = y - centerRy; } c = FloatMath.sqrt(dx*dx + dy*dy); theta = (float) Math.atan(Math.abs(dy/dx)); //if touching outside left radius and moving left stick if(c >= r && touchingLs && fingerid == lsId) { if(dx>0 && dy<0) { //top right quadrant lsX = r * FloatMath.cos(theta); lsY = -(r * FloatMath.sin(theta)); Log.i("message", "top right"); } if(dx<0 && dy<0) { //top left quadrant lsX = -(r * FloatMath.cos(theta)); lsY = -(r * FloatMath.sin(theta)); Log.i("message", "top left"); } if(dx<0 && dy>0) { //bottom left quadrant lsX = -(r * FloatMath.cos(theta)); lsY = r * FloatMath.sin(theta); Log.i("message", "bottom left"); } else if(dx > 0 && dy > 0){ //bottom right quadrant lsX = r * FloatMath.cos(theta); lsY = r * FloatMath.sin(theta); Log.i("message", "bottom right"); } } if(c >= r && touchingRs && fingerid == rsId) { if(dx>0 && dy<0) { //top right quadrant rsX = r * FloatMath.cos(theta); rsY = -(r * FloatMath.sin(theta)); Log.i("message", "top right"); } if(dx<0 && dy<0) { //top left quadrant rsX = -(r * FloatMath.cos(theta)); rsY = -(r * FloatMath.sin(theta)); Log.i("message", "top left"); } if(dx<0 && dy>0) { //bottom left quadrant rsX = -(r * FloatMath.cos(theta)); rsY = r * FloatMath.sin(theta); Log.i("message", "bottom left"); } else if(dx > 0 && dy > 0) { rsX = r * FloatMath.cos(theta); rsY = r * FloatMath.sin(theta); Log.i("message", "bottom right"); } } else { if(c < r && touchingLs && fingerid == lsId) { lsX = dx; lsY = dy; } if(c < r && touchingRs && fingerid == rsId){ rsX = dx; rsY = dy; } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: if (fingerid == lsId) { lsId = -1; lsX = 0; lsY = 0; touchingLs = false; } else if (fingerid == rsId) { rsId = -1; rsX = 0; rsY = 0; touchingRs = false; } break; } return true; } There's a left joystick and a right joystick. Right now only one will move at a time. If someone could set me on the right track I would be incredibly grateful cause I've been having nightmares about this problem.

    Read the article

  • C#.Net Calling a C++ DLL

    - by hayer
    Hi I got a DLL(without the sourcecode) which exports like this: ?ReceiveCoreDataPtr@@YAXPAX@Z ?xenoAddRigidBodyAngularImpulse@@YAXHMMM@Z ?xenoAddRigidBodyForce@@YAXHMMM@Z ?xenoAddRigidBodyForce@@YAXHMMMMMM@Z ?xenoAddRigidBodyLinearImpulse@@YAXHMMM@Z ?xenoAddRigidBodyPointImpulse@@YAXHMMMMMM@Z ?xenoAddRigidBodyTorque@@YAXHMMM@Z ?xenoCharacterControllerCrouch@@YAXH@Z ?xenoCharacterControllerJump@@YAXH@Z ?xenoCharacterDisable@@YAXH@Z ?xenoCharacterEnable@@YAXH@Z ?xenoDeleteRigidBody@@YAXH@Z ?xenoEnd@@YAXXZ ?xenoGetCameraFOV@@YAKH@Z ?xenoGetCameraPointX@@YAKH@Z ?xenoGetCameraPointY@@YAKH@Z ?xenoGetCameraPointZ@@YAKH@Z ?xenoGetCameraPositionX@@YAKH@Z ?xenoGetCameraPositionY@@YAKH@Z ?xenoGetCameraPositionZ@@YAKH@Z ?xenoGetCharacterControllerHeadPosition@@YAKH@Z ?xenoGetCharacterControllerPositionX@@YAKH@Z ?xenoGetCharacterControllerPositionY@@YAKH@Z ?xenoGetCharacterControllerPositionZ@@YAKH@Z ?xenoGetCharacterControllerRotation@@YAKH@Z ?xenoGetRigidBodyAllowedPenetrationDepth@@YAKH@Z ?xenoGetRigidBodyAngularDamping@@YAKH@Z ?xenoGetRigidBodyAngularVelocityX@@YAKH@Z ?xenoGetRigidBodyAngularVelocityY@@YAKH@Z ?xenoGetRigidBodyAngularVelocityZ@@YAKH@Z ?xenoGetRigidBodyFriction@@YAKH@Z ?xenoGetRigidBodyGravityFactor@@YAKH@Z ?xenoGetRigidBodyLinearDamping@@YAKH@Z ?xenoGetRigidBodyLinearVelocityX@@YAKH@Z ?xenoGetRigidBodyLinearVelocityY@@YAKH@Z ?xenoGetRigidBodyLinearVelocityZ@@YAKH@Z ?xenoGetRigidBodyMass@@YAKH@Z ?xenoGetRigidBodyMaxAngularVelocity@@YAKH@Z ?xenoGetRigidBodyMaxLinearVelocity@@YAKH@Z ?xenoGetRigidBodyPointVelocityX@@YAKHMMM@Z ?xenoGetRigidBodyPointVelocityY@@YAKHMMM@Z ?xenoGetRigidBodyPointVelocityZ@@YAKHMMM@Z ?xenoGetRigidBodyRestitution@@YAKH@Z ?xenoIsRigidBodyALadder@@YAHH@Z ?xenoMakeCamera@@YAXHH@Z ?xenoMakeCharacterController@@YAXHMM@Z ?xenoMakeCharacterController@@YAXHMMM@Z ?xenoMakeCharacterController@@YAXHMMMM@Z ?xenoMakeCharacterController@@YAXHMMMMM@Z ?xenoMakeCharacterController@@YAXHMMMMMM@Z ?xenoMakeCharacterController@@YAXHMMMMMMM@Z ?xenoMakeRigidBodyDynamicBox@@YAXH@Z ?xenoMakeRigidBodyDynamicBox@@YAXHM@Z ?xenoMakeRigidBodyDynamicCapsule@@YAXH@Z ?xenoMakeRigidBodyDynamicCapsule@@YAXHM@Z ?xenoMakeRigidBodyDynamicCylinder@@YAXH@Z ?xenoMakeRigidBodyDynamicCylinder@@YAXHM@Z ?xenoMakeRigidBodyDynamicSphere@@YAXH@Z ?xenoMakeRigidBodyDynamicSphere@@YAXHM@Z ?xenoMakeRigidBodyStaticBox@@YAXH@Z ?xenoMakeRigidBodyStaticCapsule@@YAXH@Z ?xenoMakeRigidBodyStaticCylinder@@YAXH@Z ?xenoMakeRigidBodyStaticSphere@@YAXH@Z ?xenoMakeRigidBodyStaticTriangleMesh@@YAXH@Z ?xenoMakeVehicle@@YAXHH@Z ?xenoMoveCharacterControllerBackward@@YAXH@Z ?xenoMoveCharacterControllerForward@@YAXH@Z ?xenoMoveCharacterControllerLeft@@YAXH@Z ?xenoMoveCharacterControllerRight@@YAXH@Z ?xenoSetCharacterControllerPosition@@YAXHMMM@Z ?xenoSetCharacterControllerRotation@@YAXHM@Z ?xenoSetGravity@@YAXM@Z ?xenoSetGravity@@YAXMMM@Z ?xenoSetRigidBodyAllowedPenetrationDepth@@YAXHM@Z ?xenoSetRigidBodyAngularDamping@@YAXHM@Z ?xenoSetRigidBodyAngularVelocity@@YAXHMMM@Z ?xenoSetRigidBodyAsLadder@@YAXHH@Z ?xenoSetRigidBodyFriction@@YAXHM@Z ?xenoSetRigidBodyGravityFactor@@YAXHM@Z ?xenoSetRigidBodyLinearDamping@@YAXHM@Z ?xenoSetRigidBodyLinearVelocity@@YAXHMMM@Z ?xenoSetRigidBodyMass@@YAXHM@Z ?xenoSetRigidBodyMaxAngularVelocity@@YAXHM@Z ?xenoSetRigidBodyMaxLinearVelocity@@YAXHM@Z ?xenoSetRigidBodyPosition@@YAXHMMM@Z ?xenoSetRigidBodyRestitution@@YAXHM@Z ?xenoSetRigidBodyRotation@@YAXHMMM@Z ?xenoSetTimeStep@@YAXM@Z ?xenoStart@@YAXH@Z ?xenoStart@@YAXHM@Z ?xenoStart@@YAXHMH@Z ?xenoStart@@YAXXZ ?xenoUpdate@@YAXXZ ?xenoVehicleAccelerate@@YAXHM@Z ?xenoVehicleHandbrake@@YAXH@Z ?xenoVehicleReverse@@YAXH@Z ?xenoVehicleTurn@@YAXHM@Z When I try to use it in another C++ App like this #include <windows.h> class XenoPhysics { private: typedef void (*FunctionFunc)(void); typedef void (*FunctionFuncFloat)(float); typedef void (*FunctionFuncInt)(int); typedef void (*FunctionIntFloatFloatFloat)(int,float,float,float); HMODULE libInstance; public: void LoadLib() { this->libInstance = LoadLibrary(L"F:\\xenophysics.dll"); } void UnloadLib() { FreeLibrary(libInstance); } void xStart() { FunctionFunc curFunc; curFunc = (FunctionFunc)GetProcAddress(this->libInstance, "?xenoStart@@YAXXZ"); curFunc(); } void xEnd() { FunctionFunc curFunc; curFunc = (FunctionFunc)GetProcAddress(libInstance, "xenoEnd"); curFunc(); } void xUpdate() { FunctionFunc curFunc; curFunc = (FunctionFunc)GetProcAddress(libInstance, "xenoUpdate"); curFunc(); } void xMakeRigidBodyStaticBox(int objid) { FunctionFuncInt curFunc; curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "xenoMakeRigidBodyStaticBox"); curFunc(objid); } void xMakeRigidBodyDynamicBox(int objid) { FunctionFuncInt curFunc; curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "xenoMakeRigidBodyDynamicBox"); curFunc(objid); } void xSetRigidBodyPosition(int objid, float x, float y, float z) { FunctionIntFloatFloatFloat curFunc; curFunc = (FunctionIntFloatFloatFloat)GetProcAddress(libInstance, "xenoSetRigidBodyPosition"); curFunc(objid, x, y, z); } void xSetGravity(float grav) { FunctionFuncFloat curFunc; curFunc = (FunctionFuncFloat)GetProcAddress(libInstance, "xenoSetGravity"); curFunc(grav); } }; This is the "wrapper"(or whatever you would call it) class.. To call the functions I'm doing XenoPhysics * d = new XenoPhysics(); d->LoadLib(); d->xStart(); It then throws the following error at me(Note that it passes the LoadLib() without any errors) Unhandled exception at 0x50261bc9 in Xeno Test.exe: 0xC0000005: Access violation reading location 0x00000064. And yes; I've checked that the "curFunc" gets the address, not just a NULL pointer(atleast I think I've checked that).. Anyone who can help out? Edit: Forgot the C#.Net code, how stupid of me :3 Here is the C++ CLR DLL "wrapper" I tried to make: #include <windows.h> // The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the XENOWRAPPERWIN32_EXPORTS // symbol defined on the command line. this symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see // XENOWRAPPERWIN32_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported. #ifdef XENOWRAPPERWIN32_EXPORTS #define XENOWRAPPERWIN32_API __declspec(dllexport) #else #define XENOWRAPPERWIN32_API __declspec(dllimport) #endif typedef void (*FunctionFunc)(); typedef void (*FunctionFuncFloat)(float); typedef void (*FunctionFuncInt)(int); typedef void (*FunctionIntFloatFloatFloat)(int,float,float,float); // This class is exported from the xeno wrapper win32.dll class XENOWRAPPERWIN32_API Cxenowrapperwin32 { public: Cxenowrapperwin32(void); HINSTANCE libInstance; // FunctionFunc curFunc; // Library base functions void LoadLib() { libInstance = LoadLibrary(L"F:\\xenophysics.dll"); } void UnloadLib() { FreeLibrary(libInstance); } // Function calls to the xeno physics void xStart() { FunctionFunc curFunc; curFunc = (FunctionFunc)GetProcAddress(libInstance, "?xenoStart@@YAXXZ"); curFunc(); } void xEnd() { FunctionFunc curFunc; curFunc = (FunctionFunc)GetProcAddress(libInstance, "?xenoEnd@@YAXXZ"); curFunc(); } void xUpdate() { FunctionFunc curFunc; curFunc = (FunctionFunc)GetProcAddress(libInstance, "?xenoUpdate@@YAXXZ"); curFunc(); } void xMakeRigidBodyStaticBox(int objid) { FunctionFuncInt curFunc; curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "?xenoMakeRigidBodyStaticBox@@YAXH@Z"); curFunc(objid); } void xMakeRigidBodyDynamicBox(int objid) { FunctionFuncInt curFunc; curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "?xenoMakeRigidBodyDynamicBox@@YAXH@Z"); curFunc(objid); } void xSetRigidBodyPosition(int objid, float x, float y, float z) { FunctionIntFloatFloatFloat curFunc; curFunc = (FunctionIntFloatFloatFloat)GetProcAddress(libInstance, "?xenoSetRigidBodyPosition@@YAXHMMM@Z"); curFunc(objid, x, y, z); } void xSetGravity(float grav) { FunctionFuncFloat curFunc; curFunc = (FunctionFuncFloat)GetProcAddress(libInstance, "?xenoSetGravity@@YAXM@Z"); curFunc(grav); } }; extern XENOWRAPPERWIN32_API int nxenowrapperwin32; XENOWRAPPERWIN32_API int fnxenowrapperwin32(void); and here is how I use it in C#.Net class xeno { [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?LoadLib@Cxenowrapperwin32@@QAEXXZ")] public static extern void xLoadLib(); public void LoadLib() { xLoadLib(); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?UnloadLib@Cxenowrapperwin32@@QAEXXZ")] public static extern void xUnloadLib(); public void UnloadLib() { xUnloadLib(); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xStart@Cxenowrapperwin32@@QAEXXZ")] public static extern void xStart(); public void Start() { xStart(); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xUpdate@Cxenowrapperwin32@@QAEXXZ")] public static extern void xUpdate(); public void Update() { xUpdate(); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xEnd@Cxenowrapperwin32@@QAEXXZ")] public static extern void xEnd(); public void End() { xEnd(); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xMakeRigidBodyDynamicBox@Cxenowrapperwin32@@QAEXH@Z")] public static extern void xMakeRigidBodyDynamicBox(int objid); public void MakeRigidBodyDynamicBox(int id) { xMakeRigidBodyDynamicBox(id); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xMakeRigidBodyStaticBox@Cxenowrapperwin32@@QAEXH@Z")] public static extern void xMakeRigidBodyStaticBox(int objid); public void MakeRigidBodyStaticBox(int id) { xMakeRigidBodyStaticBox(id); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xSetGravity@Cxenowrapperwin32@@QAEXM@Z")] public static extern void xSetGravity(float grav); public void SetGravity(float g) { xSetGravity(g); } [DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xSetRigidBodyPosition@Cxenowrapperwin32@@QAEXHMMM@Z")] public static extern void xSetRigidBodyPosition(int obj, float x, float y, float z); public void SetRigidBodyPosition(int id, float q, float w, float e) { xSetRigidBodyPosition(id, q, w, e); } } And in the main C#.Net program I do xeno tx = new xeno(); tx.Start(); tx.SetGravity(-1); tx.MakeRigidBodyStaticBox(ground.Id); tx.MakeRigidBodyDynamicBox(cube.Id); tx.SetRigidBodyPosition(cube.Id, 0, 50, 0);

    Read the article

  • Finally home - and something fully off topic

    - by Mike Dietrich
    Arrived at Munich Pasing last night at 0:50am ... finally :-) On Sunday I've left the Dylan Hotel in Dublin (thanks to the staff there as well: you were REALLY helpful!!) around 7:30pm to go to the port - and came home on Tuesday morning 1:15am. So all together 29:45hrs door-to-door - not bad for nearly 2000km just relying on public transport. And could have been faster if there were seats in ealier TGV's left. But I don't complain at all ;-) Just checked the website of Dublin Airport - it says currently: 17.00pm: Latest on flight disruptions at Dublin Airport The IAA have advised us that based on the latest Volcanic Ash Advisory Centre London Dublin Airport will remain closed for all inbound and outbound commercial flights until 20.00hours. This effectively means that no flights will land or take off at Dublin Airport until then. A further update will be posted this afternoon. When traveling I have always my iPod with me. It has gotten a bit old now (I think I've bought it 3 years ago in November 2007) but it has a 160GB hard disk in it so it fits most of my music collection (not the entire collection anymore as I'm currently re-riping everything to Apple Lossless because at least for my ears it makes a big difference - but I listen to good ol' vinyl as well ...and I don't download compressed music ;-) ). The battery of my little travel companion is still good for more than 20 hours consistent music playback - and there was a band from Texas being in my ears most of the whole journey called Midlake. I haven't heard of them before until I asked a lady at a Munich store some few weeks ago what she's playing on the speakers in the shop. She was amazed and came back with the CD cover but I hesitated to buy it as I always want to listen the tunes before - and at this day I had no time left to do so. But in Dublin I had a bit of spare time on Saturday and I always enter record stores - and the Tower Records was the sort of store I really enjoy and so I've spent there nearly two hours - leaving with 3 Midlake CDs in my bag. So if you are interested just listen those tunes which may remind some people on Fleetwood Mac: As I said in the title, fully off topic ;-)

    Read the article

  • Difficulties with rotation of a sprite

    - by Johnny
    I want to program a dolphin that jumps and rotates like a real dolphin. Jumping is not the problem, but I don't know how to make the rotation. At the moment, my dolphin rotates a little weird. But I want that it rotates like a real dolphin does. How can I improve the rotation? public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D image, water; float Gravity = 5.0F; float Acceleration = 20.0F; Vector2 Position = new Vector2(1200,720); Vector2 Velocity; float rotation = 0; SpriteEffects flip; Vector2 Speed = new Vector2(0, 0); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); image = Content.Load<Texture2D>("cartoondolphin"); water = Content.Load<Texture2D>("background"); flip = SpriteEffects.None; } protected override void Update(GameTime gameTime) { float VelocityX = 0f; float VelocityY = 0f; float time = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState kbState = Keyboard.GetState(); if(kbState.IsKeyDown(Keys.Left)) { rotation = 0; flip = SpriteEffects.None; VelocityX += -5f; } if(kbState.IsKeyDown(Keys.Right)) { rotation = 0; flip = SpriteEffects.FlipHorizontally; VelocityX += 5f; } // jump if the dolphin is under water if(Position.Y >= 670) { if (kbState.IsKeyDown(Keys.A)) { if (flip == SpriteEffects.None) { rotation += 0.01f; VelocityY += 40f; } else { rotation -= 0.01f; VelocityY += 40f; } } } else { if (flip == SpriteEffects.None) { rotation -= 0.01f; VelocityY += -10f; } else { rotation += 0.01f; VelocityY += -10f; } } float deltaY = 0; float deltaX = 0; deltaY = Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; deltaX += VelocityX * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; deltaY += -VelocityY * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; Speed = new Vector2(Speed.X + deltaX, Speed.Y + deltaY); Position += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity.X = 0; if (Position.Y + image.Height/2 > graphics.PreferredBackBufferHeight) Position.Y = graphics.PreferredBackBufferHeight - image.Height/2; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(water, new Rectangle(0, graphics.PreferredBackBufferHeight -100, graphics.PreferredBackBufferWidth, 100), Color.White); spriteBatch.Draw(image, Position, null, Color.White, rotation, new Vector2(image.Width / 2, image.Height / 2), 1, flip, 1); spriteBatch.End(); base.Draw(gameTime); } }

    Read the article

  • Difficulties with rotation of a sprite

    - by Andy
    I want to program a dolphin that jumps and rotates like a real dolphin. Jumping is not the problem, but I don't know how to make the rotation. My dolphin always rests in the same angle while it jumps. But I want that it changes the rotation during the jump, like a real dolphin does. How can I improve the rotation? public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D image, water; float Gravity = 5.0F; float Acceleration = 20.0F; Vector2 Position = new Vector2(1200,720); Vector2 Velocity; float rotation = 0; SpriteEffects flip; Vector2 Speed = new Vector2(0, 0); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); image = Content.Load<Texture2D>("cartoondolphin"); water = Content.Load<Texture2D>("background"); flip = SpriteEffects.None; } protected override void Update(GameTime gameTime) { float VelocityX = 0f; float VelocityY = 0f; float time = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState kbState = Keyboard.GetState(); if(kbState.IsKeyDown(Keys.Left)) { rotation = 0; flip = SpriteEffects.None; VelocityX += -5f; } if(kbState.IsKeyDown(Keys.Right)) { rotation = 0; flip = SpriteEffects.FlipHorizontally; VelocityX += 5f; } // jump if the dolphin is under water if(Position.Y >= 670) { if (kbState.IsKeyDown(Keys.A)) { if (flip == SpriteEffects.None) { rotation = 45; VelocityY += 40f; } else { rotation = -45; VelocityY += 40f; } } } else { VelocityY += -10f; } float deltaY = 0; float deltaX = 0; deltaY = Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; deltaX += VelocityX * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; deltaY += -VelocityY * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; Speed = new Vector2(Speed.X + deltaX, Speed.Y + deltaY); Position += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity.X = 0; if (Position.Y + image.Height/2 > graphics.PreferredBackBufferHeight) Position.Y = graphics.PreferredBackBufferHeight - image.Height/2; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(water, new Rectangle(0, graphics.PreferredBackBufferHeight -100, graphics.PreferredBackBufferWidth, 100), Color.White); spriteBatch.Draw(image, Position, null, Color.White, MathHelper.ToRadians(rotation), new Vector2(image.Width / 2, image.Height / 2), 1, flip, 1); spriteBatch.End(); base.Draw(gameTime); } }

    Read the article

  • Why doesn't my texture display with this GLSL shader?

    - by Chewy Gumball
    I am trying to display a DXT1 compressed texture on a quad using a VBO and shaders, but I have been unable to get it working. All I get is a black square. I know my texture is uploaded properly because when I use immediate mode without shaders the texture displays fine but I will include that part just in case. Also, when I change the gl_FragColor to something like vec4 (0.0, 1.0, 1.0, 1.0) then I get a nice blue quad so I know that my shader is able to set the colour. It appears to be either the texture is not being bound correctly in the shader or the texture coordinates are not being picked up. However, I can't find the error! What am I doing wrong? I am using OpenTK in C# (not xna). Vertex Shader: void main() { gl_TexCoord[0] = gl_MultiTexCoord0; // Set the position of the current vertex gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } Fragment Shader: uniform sampler2D diffuseTexture; void main() { // Set the output color of our current pixel gl_FragColor = texture2D(diffuseTexture, gl_TexCoord[0].st); //gl_FragColor = vec4 (0.0,1.0,1.0,1.0); } Drawing Code: int vb, eb; GL.GenBuffers(1, out vb); GL.GenBuffers(1, out eb); // Position Texture float[] verts = { 0.1f, 0.1f, 0.0f, 0.0f, 0.0f, 1.9f, 0.1f, 0.0f, 1.0f, 0.0f, 1.9f, 1.9f, 0.0f, 1.0f, 1.0f, 0.1f, 1.9f, 0.0f, 0.0f, 1.0f }; uint[] indices = { 0, 1, 2, 0, 2, 3 }; //upload data to the VBO GL.BindBuffer(BufferTarget.ArrayBuffer, vb); GL.BindBuffer(BufferTarget.ElementArrayBuffer, eb); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * sizeof(float)), verts, BufferUsageHint.StaticDraw); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(uint)), indices, BufferUsageHint.StaticDraw); //Upload texture int buffer = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, buffer); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Linear); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate); GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, texture.format, texture.width, texture.height, 0, texture.data.Length, texture.data); //Draw GL.UseProgram(shaderProgram); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.VertexPointer(3, VertexPointerType.Float, 5 * sizeof(float), 0); GL.TexCoordPointer(2, TexCoordPointerType.Float, 5 * sizeof(float), 3); GL.ActiveTexture(TextureUnit.Texture0); GL.Uniform1(GL.GetUniformLocation(shaderProgram, "diffuseTexture"), 0); GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);

    Read the article

  • "Hello World" in C++ AMP

    - by Daniel Moth
    Some say that the equivalent of "hello world" code in the data parallel world is matrix multiplication :) Below is the before C++ AMP and after C++ AMP code. For more on what it all means, watch the recording of my C++ AMP introduction (the example below is part of the session). void MatrixMultiply(vector<float>& vC, const vector<float>& vA, const vector<float>& vB, int M, int N, int W ) { for (int y = 0; y < M; y++) { for (int x = 0; x < N; x++) { float sum = 0; for(int i = 0; i < W; i++) { sum += vA[y * W + i] * vB[i * N + x]; } vC[y * N + x] = sum; } } } Change the function to use C++ AMP and hence offload the computation to the GPU, and now the calling code (which I am not showing) needs no changes and the overall operation gives you really nice speed up for large datasets…  #include <amp.h> using namespace concurrency; void MatrixMultiply(vector<float>& vC, const vector<float>& vA, const vector<float>& vB, int M, int N, int W ) { array_view<const float,2> a(M, W, vA); array_view<const float,2> b(W, N, vB); array_view<writeonly<float>,2> c(M, N, vC); parallel_for_each( c.grid, [=](index<2> idx) mutable restrict(direct3d) { float sum = 0; for(int i = 0; i < a.x; i++) { sum += a(idx.y, i) * b(i, idx.x); } c[idx] = sum; } ); } Again, you can understand the elements above, by using my C++ AMP presentation slides and recording… Stay tuned for more… Comments about this post welcome at the original blog.

    Read the article

  • How to use the float value from Noise function in voxel terrain?

    - by therealjohn
    Im using Unity, although this question is not really specific to that engine. Im also using an asset from the store called Coherent Noise. It has some neat noise functionality built it. I am using those functions to produce some noise values. I am getting a value between 0 and 1 (floats). I have an array of blocks (for minecraft like voxel terrain) and I am confused on how to use this float value for terrain? Do I do something like <= 0 == Solid block etc etc? I am confused on how to use the floating values that the noise functions produce to use for height values of an array of say a height of 16. Thanks for any guidance.

    Read the article

  • "Ubuntu One" Value could not be retrieved. (ValueError: cannot convert float NaN to integer)

    - by SimoneRaso
    When I try to start Ubuntu one (after the registration) I receive the this error. Plus it keeps saying "loading.." I am using Ubuntu 11.10 freshly installed. I've try to reinstall ubuntuone after remove them from "ubuntu software center" and remove all the entri ubuntuone* from synaptic. Only the last slice of the ubuntu one control panel seems responding and display "Value could not be retrieved. (ValueError: cannot convert float NaN to integer)". After I reinstall completely ubuntu and when I retry, receive the same. tank's

    Read the article

  • Developer Preview of JDK8, JavaFX8 *HARD-FLOAT ABI* for Linux/ARM Now Available!

    - by HecklerMark
    Just a quick post to spread the good word: the Developer Preview of JDK8 and JavaFX8 for Linux on ARM processors - hard-float ABI - is now available here. Right here. It's been tested on the Raspberry Pi, and many of us plan to (unofficially) test it on a variety of other ARM platforms. This could be the beginning of something big. So...what are you still doing here? Go download it already! (Did I mention you could get it here?) :-D All the best,Mark

    Read the article

  • Should I use float, double, or decimal for stats, position, etc?

    - by Ryan Peschel
    The problem with float and double is that they are not exact. If you are to do something like store replays, the values would have to be exact. The problems with decimal is that they are approximately 16x slower (confirmed by searching and personal testing) than floats and doubles. Couldn't Vector2s be another problem because they use floats internally for all the components? How do other games solve this problem? I'm sure they must use floats and doubles but aren't they not deterministic across platforms and different architecture? The replay files for games like SC2 run in a linear fashion so you cannot skip ahead so how do they solve the determinism issue with floating point numbers?

    Read the article

  • RPi and Java Embedded: Hard-Float Support is Here!!!

    - by hinkmond
    You wanted Java Embedded with Hardware Floating Point support to install on a default Raspian environment for your Raspberry Pi? Well, you just got your wish. Merry Christmas! See: Developer JDK 8 for ARM w/Hard-Float Here's a quote: The Java SE 8 Developer Preview Release for ARM including JavaFX (JDK 8) on Linux has been made available at http://jdk8.java.net. The Developer Preview is provided to the community to get feedback on the ongoing progress of the project. Developers can start developing applications using this build of Java SE 8 on an ARM device, such as the a Raspberry Pi. It's a regular JDK (Java SE 8 preview) for your Raspberry Pi, so you should note this means there is a javac (and the other typical JDK tools) available to compile your Java apps right there on the device! Woot! I'll cover step-by-step instructions how to do that in a future blog post. Stay tuned... Hinkmond

    Read the article

  • OpenCL - incremental summation during compute

    - by user1721997
    I'm absolutelly novice in OpenCL programming. For my app. (molecular simulaton) I wrote a kernel for calculate intermolecular potential of lennard-jones liquid. In this kernel I need to compute cumulative value of the potential of all particles with one: __kernel void Molsim(__global const float* inmatrix, __global float* fi, const int c, const float r1, const float r2, const float r3, const float rc, const float epsilon, const float sigma, const float h1, const float h23) { float fi0; float fi1; float d; unsigned int i = get_global_id(0); //number of particles (typically 2000) if(c!=i) { // potential before particle movement d=sqrt(pow((0.5*h1-fabs(0.5*h1-fabs(inmatrix[c*3]-inmatrix[i*3]))),2.0)+pow((0.5*h23-fabs(0.5*h23-fabs(inmatrix[c*3+1]-inmatrix[i*3+1]))),2.0)+pow((0.5*h23-fabs(0.5*h23-fabs(inmatrix[c*3+2]-inmatrix[i*3+2]))),2.0)); if(d<rc) { fi0=4.0*epsilon*(pow(sigma/d,12.0)-pow(sigma/d,6.0)); } else { fi0=0; } // potential after particle movement d=sqrt(pow((0.5*h1-fabs(0.5*h1-fabs(r1-inmatrix[i*3]))),2.0)+pow((0.5*h23-fabs(0.5*h23-fabs(r2-inmatrix[i*3+1]))),2.0)+pow((0.5*h23-fabs(0.5*h23-fabs(r3-inmatrix[i*3+2]))),2.0)); if(d<rc) { fi1=4.0*epsilon*(pow(sigma/d,12.0)-pow(sigma/d,6.0)); } else { fi1=0; } // cumulative difference of potentials fi[0]+=fi1-fi0; } } My problem is in the line: fi[0]+=fi1-fi0;. In the one-element vector fi[0] are wrong results. I read something about sum reduction, but I do not know how to do it during the calculation. Exist any simple solution of my problem?

    Read the article

  • Bitmap issue in Samsung Galaxy S3

    - by user1531240
    I wrote a method to change Bitmap from camera shot : public Bitmap bitmapChange(Bitmap bm) { /* get original image size */ int w = bm.getWidth(); int h = bm.getHeight(); /* check the image's orientation */ float scale = w / h; if(scale < 1) { /* if the orientation is portrait then scaled and show on the screen*/ float scaleWidth = (float) 90 / (float) w; float scaleHeight = (float) 130 / (float) h; Matrix mtx = new Matrix(); mtx.postScale(scaleWidth, scaleHeight); Bitmap rotatedBMP = Bitmap.createBitmap(bm, 0, 0, w, h, mtx, true); return rotatedBMP; } else { /* if the orientation is landscape then rotate 90 */ float scaleWidth = (float) 130 / (float) w; float scaleHeight = (float) 90 / (float) h; Matrix mtx = new Matrix(); mtx.postScale(scaleWidth, scaleHeight); mtx.postRotate(90); Bitmap rotatedBMP = Bitmap.createBitmap(bm, 0, 0, w, h, mtx, true); return rotatedBMP; } } It works fine in another Android device, even Galaxy Nexus but in Samsung Galaxy S3, the scaled image doesn't show on screen. I tried to mark the bitmapChange method , let it show the original size Bitmap on screen but S3 also show nothing on screen. The information of variables in eclipse is here. The information of sony xperia is here. xperia and other device is working fine.

    Read the article

  • How do I get a div to float to the bottom of its container?

    - by Stephen Martin
    I have floated images and inset boxes at the top of a container using float:right (or left) many times. Recently I hit a need to float a div at the bottom right corner of another div with the normal text wrap that you get with float (text wrapped above and to the left only). I thought this must be relatively easy even though float has no bottom value but I haven't been able to do it using a number of techniques and searching the web hasn't come up with anything other than using absolute positioning but this doesn't give the correct word wrap behaviour. I had thought this would be a very common design but apparently it isn't. If nobody has a suggestion I'll have to break my text up into separate boxes and align the div manually but that is rather precarious and I'd hate to have to do it on every page that needs it.

    Read the article

  • How to print a float number to visual c++ messagebox?

    - by karikari
    I have, a float number. I would like to print it inside a messagebox. How to do it? MessageBox(hWnd, "Result = <float>", L"Error", MB_OK); update: I do this and it prints out chinese characters inside the messagebox. float fp = 2.3333f; sprintf(buffer,"%f",fp); MessageBox(hWnd, LPCWSTR(buffer), L"Error", MB_OK);

    Read the article

  • Center directional light shadow to the cameras eye

    - by Caesar
    I'm currently drawing my directional light shadow using this view and projection: XMFLOAT3 dir((float)pitch, (float)yaw, (float)roll); XMFLOAT3 center(0.0f, 0.0f, 0.0f); XMVECTOR lightDir = XMLoadFloat3(&dir); XMVECTOR lightPos = radius * lightDir; XMVECTOR targetPos = XMLoadFloat3(&center); XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); XMMATRIX V = XMMatrixLookAtLH(lightPos, targetPos, up); // This is the view // Transform bounding sphere to light space. XMFLOAT3 sphereCenterLS; XMStoreFloat3(&sphereCenterLS, XMVector3TransformCoord(targetPos, V)); // Ortho frustum in light space encloses scene. float l = sphereCenterLS.x - radius; float b = sphereCenterLS.y - radius; float n = sphereCenterLS.z - radius; float r = sphereCenterLS.x + radius; float t = sphereCenterLS.y + radius; float f = sphereCenterLS.z + radius; XMMATRIX P = XMMatrixOrthographicOffCenterLH(l, r, b, t, n, f); // This is the projection Which works prefect if the center of my scene is at 0.0, 0.0, 0.0. What I would like to do is move the center of the scene relative to the cameras position. How can I do that?

    Read the article

  • How to rotate a sprite using multi-touch with AndEngine?

    - by 786
    I am new to Android game development. I am using AndEngine GLES-2. I have created a box with a sprite. This box is now draggable by using the code below. It works fine. But I want multi-touch on this: I want to rotate the sprite with two fingers on that box, and to keep it draggable. I've no idea how do do that, which way should I go? final float centerX = (CAMERA_WIDTH - this.mBox.getWidth()) / 2; final float centerY = (CAMERA_HEIGHT - this.mBox.getHeight()) / 2; Box = new Sprite(centerX, centerY, this.mBox, this.getVertexBufferObjectManager()) { public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { this.setPosition(pSceneTouchEvent.getX() - this.getWidth()/ 2, pSceneTouchEvent.getY() - this.getHeight() / 2); float pValueX = pSceneTouchEvent.getX(); float pValueY = CAMERA_HEIGHT-pSceneTouchEvent.getY(); float dx = pValueX - gun.getX(); float dy = pValueY - gun.getY(); double Radius = Math.atan2(dy,dx); double Angle = Radius * 360 ; Box.setRotation((float)Math.toDegrees(Angle)); return true; }

    Read the article

  • Game Input mouse filtering

    - by aaron
    I'm having a problem with filtering mouse inputs, the method I am doing right know moves the cursor back to the center of the screen each frame. But I cant do this because it messes with other things. Does anyone know how to implement this with delta mouse movement. Here is the relevant code. void update() { static float oldX = 0; static float oldY = 0; static float walkSpeed = .05f; static float sensitivity = 0.002f;//mouse sensitivity static float smooth = 0.7f;//mouse smoothing (0.0 - 0.99) float w = ScreenResolution.x/2.0f; float h = ScreenResolution.y/2.0f; Vec2f scrc(w,h); Vec2f mpos(getMouseX(),getMouseY()); float x = scrc.x-mpos.x; float y = scrc.y-mpos.y; oldX = (oldX*smooth + x*(1.0-smooth)); oldY = (oldY*smooth + y*(1.0-smooth)); x = oldX * sensitivity; y = oldY * sensitivity; camera->rotate(Vec3f(y,0,0)); transform->setRotation(transform->getRotation()*Quaternionf::fromAxisAngle(0.0f,1.0f,0.0f,-x)); setMousePosition((int)scrc.x,(int)scrc.y);//THIS IS THE PROBLEM LINE HOW CAN I AVOID THIS .... }

    Read the article

  • Normalizing the direction to check if able to move

    - by spartan2417
    i have a a room with 4 walls along the x and z axis respectively. My player who is in first person (therefore the camera) should have collision detection with these walls. I'm relatively new to this so please bare with me. I believe the way to do this is to calculate the direction and distance to the wall from the camera and then normalize the directions. However i can only get this far before i dont know what to do. I think you should work out the angle and direction your facing? where _dx and _dz is the small buffer in front of the camera. float CalcDirection(float Cam_x, float Cam_z, float Wall_x, float Wall_z) { //Calculate direction and distance to obstacle. float ob_dirx = Cam_x + _dx - Wall_x; float ob_dirz = Cam_z + _dz - Wall_z; float ob_dist = sqrt(ob_dirx*ob_dirx + ob_dirz*ob_dirz); //Normalise directions float ob_norm = sqrt(ob_dirx*ob_dirx + ob_dirz*ob_dirz); ob_dirx = (ob_dirx)/ob_norm; ob_dirz = (ob_dirz)/ob_norm; can anyone explain in laymen's terms how i work out the angle?

    Read the article

  • how to rotate a sprite using multi touch (andengine) in android?

    - by 786
    I am new to android game development. I am using andengine GLES-2. i have created sprite as a box. this box is now draggable by using this coding. it works fine. but i want multitouch on this which i want to rotate a sprite with 2 finger in that box and even it should be draggable. .... plz help someone by overwriting this code or by giving exact example of this doubt... i am trying this many days but no idea. final float centerX = (CAMERA_WIDTH - this.mBox.getWidth()) / 2; final float centerY = (CAMERA_HEIGHT - this.mBox.getHeight()) / 2; Box= new Sprite(centerX, centerY, this.mBox, this.getVertexBufferObjectManager()) { public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { this.setPosition(pSceneTouchEvent.getX() - this.getWidth()/ 2, pSceneTouchEvent.getY() - this.getHeight() / 2); float pValueX = pSceneTouchEvent.getX(); float pValueY = CAMERA_HEIGHT-pSceneTouchEvent.getY(); float dx = pValueX - gun.getX(); float dy = pValueY - gun.getY(); double Radius = Math.atan2(dy,dx); double Angle = Radius * 360 ; Box.setRotation((float)Math.toDegrees(Angle)); return true; } thanks

    Read the article

  • How to implement a 2d collision detection for Android

    - by Michael Seun Araromi
    I am making a 2d space shooter using opengl ES. Can someone please show me how to implement a collision detection between the enemy ship and player ship. The code for the two classes are below: Player Ship Class: package com.proandroidgames; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; public class SSGoodGuy { public boolean isDestroyed = false; private int damage = 0; private FloatBuffer vertexBuffer; private FloatBuffer textureBuffer; private ByteBuffer indexBuffer; private float vertices[] = { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; private float texture[] = { 0.0f, 0.0f, 0.25f, 0.0f, 0.25f, 0.25f, 0.0f, 0.25f, }; private byte indices[] = { 0, 1, 2, 0, 2, 3, }; public void applyDamage(){ damage++; if (damage == SSEngine.PLAYER_SHIELDS){ isDestroyed = true; } } public SSGoodGuy() { ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4); byteBuf.order(ByteOrder.nativeOrder()); vertexBuffer = byteBuf.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); byteBuf = ByteBuffer.allocateDirect(texture.length * 4); byteBuf.order(ByteOrder.nativeOrder()); textureBuffer = byteBuf.asFloatBuffer(); textureBuffer.put(texture); textureBuffer.position(0); indexBuffer = ByteBuffer.allocateDirect(indices.length); indexBuffer.put(indices); indexBuffer.position(0); } public void draw(GL10 gl, int[] spriteSheet) { gl.glBindTexture(GL10.GL_TEXTURE_2D, spriteSheet[0]); gl.glFrontFace(GL10.GL_CCW); gl.glEnable(GL10.GL_CULL_FACE); gl.glCullFace(GL10.GL_BACK); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisable(GL10.GL_CULL_FACE); } } Enemy Ship Class: package com.proandroidgames; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.Random; import javax.microedition.khronos.opengles.GL10; public class SSEnemy { public float posY = 0f; public float posX = 0f; public float posT = 0f; public float incrementXToTarget = 0f; public float incrementYToTarget = 0f; public int attackDirection = 0; public boolean isDestroyed = false; private int damage = 0; public int enemyType = 0; public boolean isLockedOn = false; public float lockOnPosX = 0f; public float lockOnPosY = 0f; private Random randomPos = new Random(); private FloatBuffer vertexBuffer; private FloatBuffer textureBuffer; private ByteBuffer indexBuffer; private float vertices[] = { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; private float texture[] = { 0.0f, 0.0f, 0.25f, 0.0f, 0.25f, 0.25f, 0.0f, 0.25f, }; private byte indices[] = { 0, 1, 2, 0, 2, 3, }; public void applyDamage() { damage++; switch (enemyType) { case SSEngine.TYPE_INTERCEPTOR: if (damage == SSEngine.INTERCEPTOR_SHIELDS) { isDestroyed = true; } break; case SSEngine.TYPE_SCOUT: if (damage == SSEngine.SCOUT_SHIELDS) { isDestroyed = true; } break; case SSEngine.TYPE_WARSHIP: if (damage == SSEngine.WARSHIP_SHIELDS) { isDestroyed = true; } break; } } public SSEnemy(int type, int direction) { enemyType = type; attackDirection = direction; posY = (randomPos.nextFloat() * 4) + 4; switch (attackDirection) { case SSEngine.ATTACK_LEFT: posX = 0; break; case SSEngine.ATTACK_RANDOM: posX = randomPos.nextFloat() * 3; break; case SSEngine.ATTACK_RIGHT: posX = 3; break; } posT = SSEngine.SCOUT_SPEED; ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4); byteBuf.order(ByteOrder.nativeOrder()); vertexBuffer = byteBuf.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); byteBuf = ByteBuffer.allocateDirect(texture.length * 4); byteBuf.order(ByteOrder.nativeOrder()); textureBuffer = byteBuf.asFloatBuffer(); textureBuffer.put(texture); textureBuffer.position(0); indexBuffer = ByteBuffer.allocateDirect(indices.length); indexBuffer.put(indices); indexBuffer.position(0); } public float getNextScoutX() { if (attackDirection == SSEngine.ATTACK_LEFT) { return (float) ((SSEngine.BEZIER_X_4 * (posT * posT * posT)) + (SSEngine.BEZIER_X_3 * 3 * (posT * posT) * (1 - posT)) + (SSEngine.BEZIER_X_2 * 3 * posT * ((1 - posT) * (1 - posT))) + (SSEngine.BEZIER_X_1 * ((1 - posT) * (1 - posT) * (1 - posT)))); } else { return (float) ((SSEngine.BEZIER_X_1 * (posT * posT * posT)) + (SSEngine.BEZIER_X_2 * 3 * (posT * posT) * (1 - posT)) + (SSEngine.BEZIER_X_3 * 3 * posT * ((1 - posT) * (1 - posT))) + (SSEngine.BEZIER_X_4 * ((1 - posT) * (1 - posT) * (1 - posT)))); } } public float getNextScoutY() { return (float) ((SSEngine.BEZIER_Y_1 * (posT * posT * posT)) + (SSEngine.BEZIER_Y_2 * 3 * (posT * posT) * (1 - posT)) + (SSEngine.BEZIER_Y_3 * 3 * posT * ((1 - posT) * (1 - posT))) + (SSEngine.BEZIER_Y_4 * ((1 - posT) * (1 - posT) * (1 - posT)))); } public void draw(GL10 gl, int[] spriteSheet) { gl.glBindTexture(GL10.GL_TEXTURE_2D, spriteSheet[0]); gl.glFrontFace(GL10.GL_CCW); gl.glEnable(GL10.GL_CULL_FACE); gl.glCullFace(GL10.GL_BACK); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisable(GL10.GL_CULL_FACE); } }

    Read the article

  • LibGDX onTouch() method Array and flip method

    - by johnny-b
    How can I add this on my application. i want to use the onTouch() method from the implementation of the InputProcessor to kill the enemies on screen. how do i do that? do i have to do anything to the enemy class? also i am trying to add a Array of enemies and it keeps throwing exceptions or the bullet now is facing LEFT <--- again after I used the flip method in the bullet class. All the code is below so please anyone feel free to have a look thanks. please help Thank you M // This is the bullet class. public class Bullet extends Sprite { public static final float BULLET_HOMING = 6000; public static final float BULLET_SPEED = 300; private Vector2 velocity; private float lifetime; private Rectangle bul; public Bullet(float x, float y) { velocity = new Vector2(0, 0); setPosition(x, y); AssetLoader.bullet1.flip(true, false); AssetLoader.bullet2.flip(true, false); setSize(AssetLoader.bullet1.getWidth(), AssetLoader.bullet1.getHeight()); bul = new Rectangle(); } public void update(float delta) { float targetX = GameWorld.getBall().getX(); float targetY = GameWorld.getBall().getY(); float dx = targetX - getX(); float dy = targetY - getY(); float distToTarget = (float) Math.sqrt(dx * dx + dy * dy); dx /= distToTarget; dy /= distToTarget; dx *= BULLET_HOMING; dy *= BULLET_HOMING; velocity.x += dx * delta; velocity.y += dy * delta; float vMag = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y); velocity.x /= vMag; velocity.y /= vMag; velocity.x *= BULLET_SPEED; velocity.y *= BULLET_SPEED; bul.set(getX(), getY(), getOriginX(), getOriginY()); Vector2 v = velocity.cpy().scl(delta); setPosition(getX() + v.x, getY() + v.y); setOriginCenter(); setRotation(velocity.angle()); } public Rectangle getBounds() { return bul; } public Rectangle getBounds1() { return this.getBoundingRectangle(); } } // This is the class where i load all the images from public class AssetLoader { public static Texture texture; public static TextureRegion bg, ball1, ball2; public static Animation bulletAnimation, ballAnimation; public static Sprite bullet1, bullet2; public static void load() { texture = new Texture(Gdx.files.internal("SpriteN1.png")); texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest); bg = new TextureRegion(texture, 80, 421, 395, 30); bg.flip(false, true); ball1 = new TextureRegion(texture, 0, 321, 32, 32); ball1.flip(false, true); ball2 = new TextureRegion(texture, 32, 321, 32, 32); ball2.flip(false, true); bullet1 = new Sprite(texture, 380, 350, 45, 20); bullet1.flip(false, true); bullet2 = new Sprite(texture, 425, 350, 45, 20); bullet2.flip(false, true); TextureRegion[] balls = { ball1, ball2 }; ballAnimation = new Animation(0.16f, balls); ballAnimation.setPlayMode(Animation.PlayMode.LOOP); } Sprite[] bullets = { bullet1, bullet2 }; bulletAnimation = new Animation(0.06f, aims); bulletAnimation.setPlayMode(Animation.PlayMode.LOOP); } public static void dispose() { texture.dispose(); } // This is for the rendering or drawing onto the screen/canvas. public class GameRenderer { private Bullet bullet; private Ball ball; public GameRenderer(GameWorld world) { myWorld = world; cam = new OrthographicCamera(); cam.setToOrtho(true, 480, 320); batcher = new SpriteBatch(); // Attach batcher to camera batcher.setProjectionMatrix(cam.combined); shapeRenderer = new ShapeRenderer(); shapeRenderer.setProjectionMatrix(cam.combined); // Call helper methods to initialize instance variables initGameObjects(); initAssets(); } private void initGameObjects() { ball = GameWorld.getBall(); bullet = myWorld.getBullet(); scroller = myWorld.getScroller(); } private void initAssets() { ballAnimation = AssetLoader.ballAnimation; bulletAnimation = AssetLoader.bulletAnimation; } public void render(float runTime) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); batcher.begin(); batcher.disableBlending(); batcher.enableBlending(); batcher.draw(AssetLoader.ballAnimation.getKeyFrame(runTime), ball.getX(), ball.getY(), ball.getWidth(), ball.getHeight()); batcher.draw(AssetLoader.bulletAnimation.getKeyFrame(runTime), bullet.getX(), bullet.getY(), bullet.getOriginX(), bullet.getOriginY(), bullet.getWidth(), bullet.getHeight(), 1.0f, 1.0f, bullet.getRotation()); // End SpriteBatch batcher.end(); } } // this is to load the image etc on the screen i guess public class GameWorld { public static Ball ball; private Bullet bullet; private ScrollHandler scroller; public GameWorld() { ball = new Ball(480, 273, 32, 32); bullet = new Bullet(10, 10); scroller = new ScrollHandler(0); } public void update(float delta) { ball.update(delta); bullet.update(delta); scroller.update(delta); } public static Ball getBall() { return ball; } public ScrollHandler getScroller() { return scroller; } public Bullet getBullet() { return bullet; } } //This is the input handler class public class InputHandler implements InputProcessor { private Ball myBall; private Bullet bullet; private GameRenderer aims; // Ask for a reference to the Soldier when InputHandler is created. public InputHandler(Ball ball) { myBall = ball; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean keyDown(int keycode) { return false; } @Override public boolean keyUp(int keycode) { return false; } @Override public boolean keyTyped(char character) { return false; } @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean touchDragged(int screenX, int screenY, int pointer) { return false; } @Override public boolean mouseMoved(int screenX, int screenY) { return false; } @Override public boolean scrolled(int amount) { return false; } } i am rendering all graphics in a GameRender class and a gameworld class if you need more info please let me know I am trying to make the array work but keep finding that when an array is initialized then the bullet fips back to the original and ends up being backwards???? and if I create an array I keep getting Exceptions throw??? Thank you for any help given.

    Read the article

  • CUDA: cudaMemcpy only works in emulation mode.

    - by Jason
    I am just starting to learn how to use CUDA. I am trying to run some simple example code: float *ah, *bh, *ad, *bd; ah = (float *)malloc(sizeof(float)*4); bh = (float *)malloc(sizeof(float)*4); cudaMalloc((void **) &ad, sizeof(float)*4); cudaMalloc((void **) &bd, sizeof(float)*4); ... initialize ah ... /* copy array on device */ cudaMemcpy(ad,ah,sizeof(float)*N,cudaMemcpyHostToDevice); cudaMemcpy(bd,ad,sizeof(float)*N,cudaMemcpyDeviceToDevice); cudaMemcpy(bh,bd,sizeof(float)*N,cudaMemcpyDeviceToHost); When I run in emulation mode (nvcc -deviceemu) it runs fine (and actually copies the array). But when I run it in regular mode, it runs w/o error, but never copies the data. It's as if the cudaMemcpy lines are just ignored. What am I doing wrong? Thank you very much, Jason

    Read the article

  • Rejigging a floating point equation ...

    - by Jamie
    I'd like to know if there is a way to improve the accuracy of calculating a slope. (This came up a few months back here). It seems by changing: float get_slope(float dXa, float dXb, float dYa, float dYb) { return (dXa - dXb)/(dYa - dYb); } to float get_slope(float dXa, float dXb, float dYa, float dYb) { return dXa/(dYa - dYb) - dXb/(dYa - dYb); } might be an improvement. Suggestions? Edit: It's precision I'm after, not efficiency.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >