2013年8月12日 星期一

CIImage, UIImage, CGImageRef

這三者都是Image的物件導向表示法
UIImage是用來表示iOS中的image資料,他是內建於UIKit.framework
CIImage是使用CoreImage.framework來對影片做操作的主要datatype
CGImageRef is an opaque type that represents a Quartz 2D drawing environment.

CGImageRef可以視為UIKit與CoreImage之間的介接,如下所示
UIImage *image = [imageView image];
CGImageRef cgImage = image.CGImage;
CIImage *coreImage = [CIImage imageWithCGImage:cgImage];


//從透過CIContext將CIImage繪製成CGImageRef
CGImageRef cgImage = [self.imageContext createCGImage:coreImage fromRect:[coreImage extent]];
//再由CGImageRef轉換成UIImage
[self.imageView setImage:[UIImage imageWithCGImage:cgImage]];

動態下載.pod檔

In cocos3D you can create a node from a pod file by simply executing:
[CC3PODResourceNode nodeFromResourceFile:podFileName];
 
Here you can find a full working sample.
If your pod file is available online, you could first download it locally:
NSURL *url = [NSURL URLWithString:YOUR_URL_HERE];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
 
then pass filePath to nodeFromResourceFile.
filePath identifies a file residing in the user documents directory (one of the few places where you can write files to, under iOS):
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"PODFILE.pod"];

If you want to save to a temporary directory, use:
NSTemporaryDirectory()
instead of documentsDirectory.

2013年8月9日 星期五

xcode的支援檔預設安裝位置

/Library/Application Support/Developer/Shared/Xcode/

安裝cocos3d

重點:
一,把cocos3d下載解壓
二,把cocos3d跟cocos2d放在同一層的資料夾
三,在cocos3d資料夾中以terminal執行sudo ./install-cocos3d.sh -f -2 "../cocos2d-iphone-1.0.1"
四,注意目前cocos3d 0.7.2版只可整合進cocos2d 1.x版中

Installation
------------

The cocos3d framework is built on cocos2d 1.x. Before installing cocos3d,
you must download and install the cocos2d 1.x SDK from:

http://www.cocos2d-iphone.org/download

*** PLEASE NOTE THAT cocos3d 0.7.2 IS NOT COMPATIBLE WITH cocos2d 2.x. ***
***     BE SURE TO DOWNLOAD cocos2d 1.x FOR USE WITH cocos3d.          ***

Unzip the cocos3d distribution file (which you've probably already done,
otherwise you wouldn't be reading this document).

Open a Terminal session, navigate to the unzipped cocos3d distribution
directory and run the install-cocos3d script as follows:

./install-cocos3d.sh -f -2 "path-to-cocos2d-sources"

For example:

./install-cocos3d.sh -f -2 "../../cocos2d/cocos2d-iphone-1.1"

The cocos2d source code must be available and identified using the -2 switch so that the
installer can link the cocos2d libraries to the cocos3d templates and demo projects.

If you encounter 'rsync' errors during installation, it's typically because you are trying
to run the installer without first navigating to the cocos3d distribution directory.
Be sure to run the installer from the cocos3d distribution directory.

That's it!

安裝及移除cocos2d

A. cocos2d 官網: http://www.cocos2d-iphone.org/

B. 下載穩定版本(Stable version): http://www.cocos2d-iphone.org/download

C. 安裝方式:
   1. 解壓縮下載的檔案: cocos2d-iphone-1.0.1.tar.gz
   2. 在 Terminal 下, 到解壓縮目錄內執行:
       $ cd cocos2d-iphone-1.0.1.tar.gz
        $ sudo ./install-templates.sh
   3. 可以看到以下的安裝訊息:
      Installing cocos2d template:
      /Library/Application Support/Developer/Shared/Xcode/Project Templates/cocos2d 0.99.4/cocos2d Application/

      Installing cocos2d + box2d template:
      /Library/Application Support/Developer/Shared/Xcode/Project Templates/cocos2d 0.99.4/cocos2d Box2d Application/

      Installing cocos2d + chipmunk template:
      /Library/Application Support/Developer/Shared/Xcode/Project Templates/cocos2d 0.99.4/cocos2d Chipmunk Application/

      creating destination directory:
      /Library/Application Support/Developer/Shared/Xcode/File Templates/cocos2d 0.99.4/

D. 移除方式:
   刪除: C 安裝後所產生的目錄即可.

轉貼來源:http://itouchs.blogspot.com/2010/11/iphone-16-cocos2d.html

2013年8月6日 星期二

Calculate the MD5 Hash of a String in Objective-C

#import <CommonCrypto/CommonDigest.h>

- (NSString *) encodeString:(NSString *) s {
   const char *cStr = [s UTF8String];
   unsigned char result[CC_MD5_DIGEST_LENGTH];
   CC_MD5(cStr, strlen(cStr), result);
   NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
   for(int i = 0; i < CC_MD5_DIGEST_LENGTH; ++i) {
      [result appendFormat:@"%02x", result[i]];
   }       
   return [NSString stringWithString:result];
}      

2013年8月5日 星期一

動態匯入QCAR資料庫

(尚未實際測試)
just download that file from network, store it within application directories and load it like the sample data bundled with the app

NSString * pathToDownloadedFile; //should have path to your file

QCAR::DataSet *dataSet = nil;
QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>    (trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
dataSet = imageTracker->createDataSet();
dataSet->load([pathToDownloadedFile cStringUsingEncoding:NSASCIIStringEncoding], QCAR::DataSet::STORAGE_ABSOLUTE);


imageTracker->activateDataSet(dataSet);