CelestiaSimulation.mm
上传用户:center1979
上传日期:2022-07-26
资源大小:50633k
文件大小:6k
源码类别:

OpenGL

开发平台:

Visual C++

  1. //
  2. //  CelestiaSimulation.mm
  3. //  celestia
  4. //
  5. //  Created by Bob Ippolito on Fri Jun 07 2002.
  6. //  Copyright (c) 2002 Chris Laurel. All rights reserved.
  7. //
  8. #import "CelestiaSimulation.h"
  9. #import "CelestiaSimulation_PrivateAPI.h"
  10. #import "CelestiaUniversalCoord_PrivateAPI.h"
  11. #import "CelestiaSelection_PrivateAPI.h"
  12. #import "CelestiaUniverse_PrivateAPI.h"
  13. #import "CelestiaObserver_PrivateAPI.h"
  14. #import "CelestiaVector_PrivateAPI.h"
  15. #import "NSString_ObjCPlusPlus.h"
  16. #import "Astro.h"
  17. /*
  18. void gotoLocation(const RigidTransform& transform, double duration);
  19. void setFrame(const FrameOfReference&);
  20. FrameOfReference getFrame() const;
  21. */
  22. @implementation CelestiaSimulation(PrivateAPI)
  23. -(CelestiaSimulation *)initWithSimulation:(Simulation *)sim 
  24. {
  25.     self = [super init];
  26.     _data = [[NSValue alloc] initWithBytes:reinterpret_cast<void*>(&sim) objCType:@encode(Simulation*)];
  27.     return self;
  28. }
  29. -(Simulation *)simulation
  30. {
  31.     return reinterpret_cast<Simulation*>([_data pointerValue]);
  32. }
  33. @end
  34. @implementation CelestiaSimulation
  35. -(void)dealloc
  36. {
  37.     if (_data != nil)
  38.     {
  39.         [_data release];
  40.         _data = nil;
  41.     }
  42.     [super dealloc];
  43. }
  44. -(NSNumber*)julianDate
  45. {
  46.     return [NSNumber numberWithDouble:[self simulation]->getTime()];
  47. }
  48. -(void)setDate:(NSNumber*)t
  49. {
  50.     [self simulation]->setTime([t doubleValue]);
  51. }
  52. -(NSNumber*)getTimeScale
  53. {
  54.     return [NSNumber numberWithDouble:[self simulation]->getTimeScale()];
  55. }
  56. -(NSNumber*)realTime
  57. {
  58.     return [NSNumber numberWithDouble:[self simulation]->getRealTime()];
  59. }
  60. -(NSNumber*)arrivalTime
  61. {
  62.     return [NSNumber numberWithDouble:[self simulation]->getArrivalTime()];
  63. }
  64. -(void)update:(NSNumber*)dt
  65. {
  66.     [self simulation]->update([dt doubleValue]);
  67. }
  68. -(CelestiaSelection*)pickObject:(CelestiaVector*)pickRay tolerance:(NSNumber*)tolerance
  69. {
  70.     return [[[CelestiaSelection alloc] initWithSelection:[self simulation]->pickObject([pickRay vec3f],[tolerance floatValue])] autorelease];
  71. }
  72. -(CelestiaSelection*)pickObject:(CelestiaVector*)pickRay
  73. {
  74.     return [self pickObject:pickRay tolerance:[NSNumber numberWithDouble:0.0]];
  75. }
  76. -(CelestiaUniverse*)universe
  77. {
  78.     Universe* uni = [self simulation]->getUniverse();
  79.     if (uni == NULL)
  80.         return nil;
  81.     return [[[CelestiaUniverse alloc] initWithUniverse:uni] autorelease];
  82. }
  83. -(void)orbit:(CelestiaVector*)q
  84. {
  85.     [self simulation]->orbit([q quatf]);
  86. }
  87. -(void)rotate:(CelestiaVector*)q
  88. {
  89.     [self simulation]->rotate([q quatf]);
  90. }
  91. -(void)changeOrbitDistance:(NSNumber*)d
  92. {
  93.     [self simulation]->changeOrbitDistance([d floatValue]);
  94. }
  95. -(void)setTargetSpeed:(NSNumber*)s
  96. {
  97.     [self simulation]->setTargetSpeed([s floatValue]);
  98. }
  99. -(NSNumber*)targetSpeed
  100. {
  101.     return [NSNumber numberWithDouble:[self simulation]->getTargetSpeed()];
  102. }
  103. -(CelestiaSelection*)selection
  104. {
  105.     return [[[CelestiaSelection alloc] initWithSelection:[self simulation]->getSelection()] autorelease];
  106. }
  107. -(void)setSelection:(CelestiaSelection*)sel
  108. {
  109.     [self simulation]->setSelection([sel selection]);
  110. }
  111. -(CelestiaSelection*)trackedObject
  112. {
  113.     return [[[CelestiaSelection alloc] initWithSelection:[self simulation]->getTrackedObject()] autorelease];
  114. }
  115. -(void)setTrackedObject:(CelestiaSelection*)sel
  116. {
  117.     [self simulation]->setTrackedObject([sel selection]);
  118. }    
  119. -(void)selectPlanet:(NSNumber*)planetNo
  120. {
  121.     [self simulation]->selectPlanet([planetNo intValue]);
  122. }
  123. -(CelestiaSelection*)findObject:(NSString*)s
  124. {
  125.     return [[[CelestiaSelection alloc] initWithSelection:[self simulation]->findObject([s stdString])] autorelease];
  126. }
  127. -(CelestiaSelection*)findObjectFromPath:(NSString*)s
  128. {
  129.     return [[[CelestiaSelection alloc] initWithSelection:[self simulation]->findObjectFromPath([s stdString], true)] autorelease];
  130. }
  131. -(void)gotoSelection:(NSNumber*)gotoTime up:(CelestiaVector*)up coordinateSystem:(NSString*)csysName
  132. {
  133.     [self simulation]->gotoSelection(
  134.         [gotoTime doubleValue],
  135.         [up vec3f],
  136.         (ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:csysName] intValue]);
  137. }
  138. -(void)gotoSelection:(NSNumber*)gotoTime distance:(NSNumber*)distance up:(CelestiaVector*)up coordinateSystem:(NSString*)csysName
  139. {
  140.     [self simulation]->gotoSelection(
  141.         [gotoTime doubleValue],
  142.         [distance doubleValue],
  143.         [up vec3f], 
  144.         (ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:csysName] intValue]);
  145. }
  146. -(void)gotoSelection:(NSNumber*)gotoTime distance:(NSNumber*)distance longitude:(NSNumber*)longitude latitude:(NSNumber*)latitude up:(CelestiaVector*)up
  147. {
  148.     [self simulation]->gotoSelectionLongLat(
  149.         [gotoTime doubleValue],
  150.         [distance doubleValue],
  151.         [longitude floatValue],
  152.         [latitude floatValue],
  153.         [up vec3f]);
  154. }
  155. -(NSArray*)getSelectionLongLat
  156. {
  157.     double distance, longitude, latitude;
  158.     [self simulation]->getSelectionLongLat(distance, longitude, latitude);
  159.     return [NSArray arrayWithObjects:[NSNumber numberWithDouble:distance],[NSNumber numberWithDouble:longitude],[NSNumber numberWithDouble:latitude],nil];
  160. }
  161. -(void)centerSelection
  162. {
  163.     [self simulation]->centerSelection();
  164. }
  165. -(void)centerSelection:(NSNumber*)centerTime
  166. {
  167.     [self simulation]->centerSelection([centerTime doubleValue]);
  168. }
  169. -(void)follow
  170. {
  171.     [self simulation]->follow();
  172. }
  173. -(void)geosynchronousFollow
  174. {
  175.     [self simulation]->geosynchronousFollow();
  176. }
  177. -(void)phaseLock
  178. {
  179.     [self simulation]->phaseLock();
  180. }
  181. -(void)chase
  182. {
  183.     [self simulation]->chase();
  184. }
  185. -(void)cancelMotion
  186. {
  187.     [self simulation]->cancelMotion();
  188. }
  189. -(CelestiaObserver*)observer
  190. {
  191.     return [[[CelestiaObserver alloc] initWithObserver:[self simulation]->getObserver()] autorelease];
  192. }
  193. -(void)setObserverPosition:(CelestiaUniversalCoord*)uc
  194. {
  195.     [self simulation]->setObserverPosition([uc universalCoord]);
  196. }
  197. -(void)setObserverOrientation:(CelestiaVector*)q
  198. {
  199.     [self simulation]->setObserverOrientation([q quatf]);
  200. }
  201. -(void)setObserverMode:(NSString*)m
  202. {
  203.     [self simulation]->setObserverMode([m isEqualToString:@"Free"] ? Observer::Free : Observer::Travelling);
  204. }
  205. -(NSString*)observerMode
  206. {
  207.     return ([self simulation]->getObserverMode() == Observer::Free) ? @"Free" : @"Travelling";
  208. }
  209. -(void)setFrame:(NSString*)cs selection:(CelestiaSelection*)sel
  210. {
  211.     [self simulation]->setFrame((ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:cs] intValue], [sel selection]);
  212. }
  213. @end