It looks like my old thread disappeared, so here’s a new one for all the coders out there. Use this thread for anything relating to programming, especially if you’re looking for help. Speaking of which…
I’m in the middle of tweaking a game I made for Windows 7 phones using XNA, and I’m trying to make the controls more precise. In my game, I move a ball around by sliding the cursor (I’m using the phone emulator). Currently, there are a few problems:
[LIST=1]
[]The ball moves a bit too much when I make even slight movements
[]If I slide in a direction when the cursor is not on the ball, the ball will move in that direction. The ball should move only when the cursor is on the ball.
[/LIST]
I think I can figure out #2 fairly quickly as there’s a way to get the position of where the user touched the screen. #1 is a bit more troublesome. I do have a variable to adjust the slide distance before any movement is registered, but I don’t think that’s enough. I’ll try increasing the slide distance further and see where that goes. Here’s the code I’m using:
Input code
Spoiler
protected override void SetupInputs() //TODO: make controls good!
{
float slideDistance = 20.0f;
//Code for sliding to the left
input.AddTouchSlideInput(ActionMoveLeft, Input.Direction.Left, slideDistance);
//input.AddTouchGestureInput(ActionMoveRight, GestureType.Tap, ScreenRightHalf);
//Code for sliding to the right
input.AddTouchSlideInput(ActionMoveRight, Input.Direction.Right, slideDistance);
//input.AddTouchGestureInput(ActionMoveLeft, GestureType.Tap, ScreenLeftHalf);
//Code for sliding up
input.AddTouchSlideInput(ActionMoveUp, Input.Direction.Up, slideDistance);
//Code for sliding down
input.AddTouchSlideInput(ActionMoveDown, Input.Direction.Down, slideDistance);
//Code for restarting level
input.AddTouchGestureInput(ActionRestart, GestureType.Tap, restartButton.TouchArea);
}
Well wouldn’t you want to determine the amount the finger is sliding, based on movement of the finger over time and then give the ball a velocity based on that. So if the finger slides a further distance, and faster, than the ball would move faster in that direction, thus going further. It wouldn’t hurt to just toss in some basic physics stuff (like slowing down) for this. Did you just want theory, or do you want some pseudo code or something?
If your getting messages from the phone that you recognize as a swipe or whatnot you could do something like:
if(currentmsg == msg.Swipe)
{
//Test for if the ball is being touched or another part of the screen.
if(Ball.Contains(currentmsg.location))
{
//Ball code
}
else
{
//other stuff on swipe
}
}
If you expand your code to take into account more items you’ll need to do some arrays to hold a universal item type (like hold all the balls on screen to iterate through those that are relevant) or something if you really want to keep your items organized and somehow cull items that won’t matter at the time so your not iterating through every possible item but don’t know if that’s your end goal for this kind of stuff.
As for bad movement that has to do with the numbers you are using to move it and/or possibly not having decent physics so it seems off/unrealistic to you. Are you wanting it to follow your finger or roll in the direction based on how big the swipe is or what? Typically something like this is done by using the distance swiped to estimate a force,velocity, or acceleration of the ball and than just let the physics you program for the ball take care of itself.
void Ball::OnSwipe(Swipe* s)
{
//Function that transforms swipe information to something
//Useful for your game logic
Point force = GetForce(s);
//A bit oversimplified but should get the point across as this is just pseudo code
Ball.Acceleration += force/Ball.Mass;
}
void Ball::OnUpdate(float dt)
{
//Need logic to lessen the acceleration but because
//the acceleration will have negative/positive qualities the logic will be a bit more complex than simply subtracting a constant
Ball.Move(Ball.Acceleration);
Ball.ReduceAcceleration(Constant*dt);
}
Does anyone know how bone modeling is typically programmed? My current projects do it mainly all on CPU as the only ways I’ve thought to do it on the GPU are quite obtuse/crappy performance. Done some 2D projects before and some minor 3d stuff before, but wanting to up my game a bit and programming bone models would do a lot to add to the quality of my projects.
Maybe someone knows a book that specializes on just this subject? I’ve got some stuff working alright but it’s going slower than I’d like it too and constantly am trying to add to it because I didn’t think it through as well as I should have on my first try.
Just a hobbyist but trying to get something a bit more real made with some people I’m talking too.
When I try to search for more info on AddTouchSlideInput, the only results are basically this thread; is this XNA API code? It’s been awhile since I worked with XNA.
Sorry, should’ve mentioned this before…My game (in its current state…a prototype) doesn’t use any sort of physics, so the ball moves at fixed points. Kinda like how a checker piece moves on a board. The ball moves on tiles, so there’s no acceleration involved.
Sounds like you need to just tinker with your constants than or tinker with a way of turning the swipe into moving a certain number of spaces in a direction. Lots of ways you could go about it. Also just because you use a tile system for background or whatnot doesn’t mean the ball has to be on a tile. Just can use it control an independent quad which uses an acceleration type system, pretty simple/low overhead. Than you used your tile background as a way to do easy collision detection. Again though just depends on what your trying to do, not a lot of clear description on that from you.
The problem with it moving too far is likely your points are too far away or you’re hitting edge cases. IE if you move a very small amount(less than a point) the minimum distance you can travel is still 1 point so it moves farther than you moved your finger. Or if you’re finger barely goes 2 points you might be moving the ball a full two points or something and this error in precision is only noticeable when you do very small movements. Those are just assumptions though since like sephiroth said it’s not entirely clear what you’re trying to do.
edit: though looking at it again your slide distance is a float, so not sure how you’re using these points to snap too instead of physics.
edit again: also for the bones question what do you mean by the programming? creation and animation wise 3dsmax is widely used, for actually animating it in code I’d recommend looking up SLERP, though I imagine there’s a way to make the API handle it for you.
edit the third: I thought I’d offer solutions, either man up and use real physics(unless the checker board movement is an actual design decisions). Movement physics is really easy and I can help with that if you’d like. Or make your units smaller, this will help with precision, IE add more points and make them closer together.
This is the problem I’m having right here. I want the ball to follow the cursor’s movements without getting ahead of it. Currently I’ve increased the slide distance but that doesn’t really solve the issue and just makes the controls cumbersome. I’ll explain what the game is about so you guys can better understand the problem.
My game is called Tile Crusher. The objective is to destroy tiles by rolling over them with a ball. The trick is to destroy all breakable tiles in a level with as few movements as possible and without backtracking. If you backtrack onto a destroyed tile, it will be restored and must be broken again. By design, I’m not using any sort of physics because it’s not the kind of game that needs it.
I have special tile types, such as tiles that must be rolled over more than once before they break, but I wanted to get the control issues fixed first before I continue. As a prototype, I have the core gameplay finished, but I plan to finish the game for my portfolio and possibly sell the game on the Marketplace.
This thread is relevant to my interests. I am merely posting to subscribe for now. I am not really any good at programming but am learning well and jump at every opportunity to examine code. Great thread!
Alright so if I were to drag my finger 3 tiles to the right the ball should move 3 tiles to the right correct(if this is not correct how exactly are you converting ‘swipes’ to ball movement and how are you actually moving the ball)? Does the sliding go too far every time or just when you give it tiny finger movements?
Yeah, it’s the number of pixels that’s read before movement is registered. The lower the number, the less effort it takes the move the ball. Each tile is 80x80 pixels. The ball uses the same dimensions.
That’s the goal I’m trying to achieve. The ball to cursor/, finger movement should be 1:1, you know? The ball tends to get ahead of my cursor if I make small movements, which is what I’m trying to fix.
Basically, I need to check the cursor’s position against the ball’s position and move the ball only if the cursor’s position is within the range of the ball’s dimensions.
alright, so how do you check how many tiles the swipe is and how do you move the ball, and what do you do if the swip goes say 1.1 tiles, do you move it 2 tiles or 1?
I understand the idea of this thread. But the right place for answers others might know is really some place dedicated to the topic. like stackoverflow.com . Someone there may be able to answer definitively about API nuances. Though if it is an edge case with your code always moving a minimum pixels you’ll have to find it.
If a square is 80 pixels wide, but you have the movement set to 20 pixels in order to call the move function, then your ball is going to move 4 squares for every 1 square you slide your finger, making it appear to move super sensitive
Well I gues to really answer your question we should have asked what kind of number your input reads because without knowing that we can’t give really definitive feedback. I honestly don’t see any code that is getting back a value, but i’m not familiar with api so some of that code could be changing some of the values being given to it internally. Personally I think that’s bad practice though as it makes code/bugs hard to read/find.
Also looking at your code you seem to be giving us the setup code not the actual working code. Which is probably why people aren’t understanding it. The code looks like your just registering some inputs into some sort of input handler so you can later call them from some tag/function or whatever.
I say that because the code has no restriction on which functions are called as far as I can see, unless some of those variables are evaluated for control within the functions. So each function moves 20 points no matter what. Which should result in no movement. This makes me think that their must be more input related code other places.
Mean for importing the animation. Making the animation is fairly straightforward though lengthy process. I’m just a bit confused on how I turn matrix transformation data for each bone into something that transforms one unified mesh, only way I’ve thought of doing it is have the program procedurely break into smaller sub-meshes that are centered at the origin than have each have a transformation applied to them than sum the differences between each vertex together so you get the net movement. I highly doubt there isn’t a more efficient way but it’s the only way when thinking of it i could fathom how to do it. I’ll check out SLERP see what it’s about.
ah alright, mesh hierarchy is the way to go then, I believe the easiest way is to keep multiplying the transformation matrices by each other as you go down the hierarchy. IE you have the identity, multiply it by the transformation matrix for the body, then apply it to the body, then multiply the arm transformation matrix onto that and multiply the arm by the combination of the body and arm transformation matrix. Directx WILL do all this for you but you I recommend writing it yourself, it’s super hard to debug the directx sdk for this and you CAN mess it up(I let directx do it for me and regretted it). There’s tutorials online for importing from common formats that are pretty solid.
SLERP is an interpolation, it’s how you get from one frame of animation to the next.
I’m not quite sure what you’re asking so I’m going to throw out some different answers and hope I hit what you’re looking for.
3D modeling can be done with a dedicated program like Maya, 3DS Max, Blender, Lightwave, Modo, etc.) or an application component (Shaper, Lofter) or scene description language (POV-Ray). I don’t think that’s what you’re asking though…
If you are asking for the specific bone modeling process – Basically CT scans of healthy bones and fractured bones are made to work out the mathematical algorithm for the exact displacement and rotation of each bone fragment. Object boundaries are created using an ‘interactive segmentation’ method. Soft tissues around the bone are usually traced manually. Then the 3D mesh models are created with surface rendering. (The above is usually done with a dedicated software program) These models are then exported to AutoCAD, 3DS Max, Wavefront, MeshLab, VRML, etc. etc. depending on how the data is to be applied.
If you are asking how the modeling software is programmed – These programs are mostly written in C / C++.
If you are asking how the actual files work – Depending on filetype they, for example, mainly consist of a header followed by a list of vertices and then a list of polygons. The header specifies how many vertices and polygons are in the file, and also states what properties are associated with each vertex, such as (x,y,z) coordinates, normals and color. The polygon faces are simply lists of indices into the vertex list, and each face begins with a count of the number of elements in each list.
Hope that helps! Sorry if I’ve completely missed the mark but hopefully I’ve answered your question.
lol bone modeling while literally means what you describe, traditionally describes a 3d object who has an outermesh referred to as a “skin” but is controlled by multiple less complicated subobjects referred to as “bones”. Interesting answer though, didn’t expect that.
Ya, you know of a decent one that you could link me by chance? On Slerp thought it might’ve been a toolkit/api or something googled it and found out it wasn’t.