
Originally Posted by
drunknbass
can you post a code sample... id like to see
I can't post the code from iPhysics, as it's quite tied up with the rest of the code, but here goes my testing code.
EDApplication.h:
Code:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
struct GSPathPoint {
char unk0;
char unk1;
short int status;
int unk2;
float x;
float y;
};
typedef struct {
int unk0;
int unk1;
int type;
int subtype;
float unk2;
float unk3;
float x;
float y;
int timestamp1;
int timestamp2;
int unk4;
int modifierFlags;
int unk5;
int unk6;
int mouseEvent;
short int dx;
short int fingerCount;
int unk7;
int unk8;
char unk9;
char numPoints;
short int unk10;
struct GSPathPoint points[10];
} GSEvent;
@interface EDView : UIView {
CGPoint fingers[5];
int numFingers;
}
- (void)dumpEvent:(GSEvent*)event;
@end
@interface EDApplication : UIApplication {
EDView *vw;
}
@end EDApplication.m:
Code:
#import "EDApplication.h"
#include <stdlib.h>
#include <math.h>
@implementation EDApplication
- (void) applicationDidFinishLaunching: (id) unused {
[UIHardware _setStatusBarHeight:0.0f];
[self setStatusBarMode:2 orientation:0 duration:0.0f fenceID:0];
UIWindow *window;
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
window = [[UIWindow alloc] initWithContentRect: rect];
vw = [[EDView alloc] initWithFrame: rect];
[window orderFront: self];
[window makeKey: self];
[window _setHidden: NO];
[window setContentView: vw];
}
@end
#define DUMP_LINES 10
@implementation EDView
- (void)dumpEvent:(GSEvent*)event {
/* Test 1: Dump raw data
char tmp[256];
int l, i;
char *bytes = (char *)event;
for (l = 0; l < DUMP_LINES; l++) {
tmp[0] = 0;
for (i = 0; i < 8; i++) {
sprintf(tmp, "%s %02X", tmp, *(bytes++));
}
sprintf(tmp, "%s -", tmp);
for (i = 0; i < 8; i++) {
sprintf(tmp, "%s %02X", tmp, *(bytes++));
}
NSLog(@"%s", tmp);
}
*/
/* Test 2: Simple events
NSLog(@"MouseEvent: %d, fingerCount: %hd, numPoints: %hhd, pos: %f, %f", event->mouseEvent, event->fingerCount, event->numPoints, event->x, event->y);
int i;
for (i = 0; i < event->numPoints; i++) {
NSLog(@" Point %d: %f, %f", i + 1, event->points[i].x, event->points[i].y);
}
*/
/* Test 3: Multi-mouse tracking
int i, j;
bool oks[5] = {false, false, false, false, false};
for (i = 0; i < event->fingerCount; i++) {
bool found = false;
for (j = 0; j < numFingers; j++) {
int dist = ABS(event->points[i].x - fingers[j].x) + ABS(event->points[i].y - fingers[j].y);
if (dist < 20) {
found = true;
oks[j] = true;
if (dist > 2) {
fingers[j].x = event->points[i].x;
fingers[j].y = event->points[i].y;
// MOUSEMOVE
NSLog(@"MouseMove: %d, pos: %f, %f", j, fingers[j].x, fingers[j].y);
}
break;
}
}
if (!found) {
fingers[numFingers].x = event->points[i].x;
fingers[numFingers].y = event->points[i].y;
oks[numFingers] = true;
numFingers++;
// MOUSEDOWN
NSLog(@"MouseDown: %d, pos: %f, %f", numFingers, fingers[numFingers-1].x, fingers[numFingers-1].y);
}
}
for (j = 0; j < numFingers; j++) {
if (!oks[j]) {
// MOUSEUP
NSLog(@"MouseUp: %d, pos: %f, %f", j + 1, fingers[j].x, fingers[j].y);
numFingers--;
fingers[j].x = fingers[numFingers].x;
fingers[j].y = fingers[numFingers].y;
oks[j] = oks[numFingers];
j--;
}
}
*/
}
- (id)initWithFrame:(struct CGRect)frame {
[super initWithFrame: frame];
numFingers = 0;
[super setTapDelegate: self];
[super setGestureDelegate: self];
return self;
}
- (void)gestureChanged:(GSEvent*)event {
NSLog(@"gestureChanged:");
[self dumpEvent: event];
}
- (void)gestureEnded:(GSEvent*)event {
NSLog(@"gestureEnded:");
[self dumpEvent: event];
}
- (void)gestureStarted:(GSEvent*)event {
NSLog(@"gestureStarted:");
[self dumpEvent: event];
}
- (void)mouseDown:(GSEvent*)event {
NSLog(@"mouseDown:");
[self dumpEvent: event];
}
- (void)mouseDragged:(GSEvent*)event {
NSLog(@"mouseDragged:");
[self dumpEvent: event];
}
- (void)mouseEntered:(GSEvent*)event {
NSLog(@"mouseEntered:");
[self dumpEvent: event];
}
- (void)mouseExited:(GSEvent*)event {
NSLog(@"mouseExited:");
[self dumpEvent: event];
}
- (void)mouseMoved:(GSEvent*)event {
NSLog(@"mouseMoved:");
[self dumpEvent: event];
}
- (void)mouseUp:(GSEvent*)event {
NSLog(@"mouseUp:");
[self dumpEvent: event];
}
- (void)view:(UIView *)view handleTapWithCount:(int)count event:(GSEvent *)event {
NSLog(@"handleTapWithCount: %d", count);
[self dumpEvent: event];
}
- (double)viewTouchPauseThreshold:(UIView *)view {
return 0.5;
}
- (BOOL)isFirstResponder {
return YES;
}
@end main.m:
Code:
#import <UIKit/UIKit.h>
#import "EDApplication.h"
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
return UIApplicationMain(argc, argv, [EDApplication class]);
} Just uncomment one of the test blocks and have fun... Test 3 is not very accurate, but you can get the idea.

Originally Posted by
Gregsen
maybe i dont get it because im new to iphysics, but how exactly do i manage to move more then one field simultanously? When i draw something and then touch it i can move it, but when i touch the screen in another place at the same time to draw something other or move another object it just doesnt react.
Does this only works with special levels or what else am i doing wrong?
Right now I'm not implementing any new input style, so all drawing and stuff is just for 1 touch mode. Where multi-touch is going to be used now is in triggers, which can be used as on-screen buttons, in single and multi-player games... But I welcome suggestions on how to use multi-touch to make more interesting input methods...
Bookmarks