Skip to content

Commit

Permalink
feat(ContextServrice): Added 'createGeoEntity’
Browse files Browse the repository at this point in the history
  • Loading branch information
speigg committed Apr 29, 2017
2 parents 96b127c + ebb381a commit 00c5f3f
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/context.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="cesium" />
import { Entity, EntityCollection, Cartographic, Cartesian3, Quaternion, JulianDate, ReferenceFrame } from './cesium/cesium-imports';
import { Entity, EntityCollection, Cartographic, Cartesian3, Quaternion, Transforms, JulianDate, ReferenceFrame } from './cesium/cesium-imports';
import { SerializedEntityState, SerializedEntityStateMap, ContextFrameState, GeolocationOptions } from './common';
import { SessionService, SessionPort } from './session';
import { Event } from './utils';
Expand Down Expand Up @@ -233,6 +233,28 @@ export declare class ContextService {
* Get the cartographic position of an Entity
*/
getEntityCartographic(entity?: Entity, cartographic?: Cartographic): Cartographic | undefined;
private _scratchMatrix3;
private _scratchMatrix4;
/**
* Create an entity that is positioned at the given cartographic location,
* with an orientation computed according to the given local to fixed frame converter.
*
* For the localFrameToFixedFrame parameter, Cesium provides the following:
*
* Cesium.Transforms.eastNorthUpToFixedFrame
* Cesium.Transforms.northEastDownToFixedFrame
* Cesium.Transforms.northUpEastToFixedFrame
* Cesium.Transforms.northWestUpToFixedFrame
*
* Additionally, argon.js provides:
*
* Argon.eastUpSouthToFixedFrame
*
* Alternative transform functions can be created with:
*
* Cesium.Transforms.localFrameToFixedFrameGenerator
*/
createGeoEntity(cartographic: Cartographic, localFrameToFixedFrame: typeof Transforms.northUpEastToFixedFrame): Entity;
/**
* Create a new EntityPose instance to represent the pose of an entity
* relative to a given reference frame. If no reference frame is specified,
Expand Down
43 changes: 42 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
Cartesian3,
Quaternion,
Matrix4,
Matrix3,
CesiumMath,
Transforms,
JulianDate,
ReferenceFrame,
PerspectiveFrustum,
Expand All @@ -18,7 +20,7 @@ import {
import {
DEFAULT_NEAR_PLANE,
DEFAULT_FAR_PLANE,
SerializedEntityState,
SerializedEntityState,
SerializedEntityStateMap,
SubviewType,
ContextFrameState,
Expand Down Expand Up @@ -521,6 +523,45 @@ export class ContextService {
return undefined;
}

private _scratchMatrix3 = new Matrix3;
private _scratchMatrix4 = new Matrix4;

/**
* Create an entity that is positioned at the given cartographic location,
* with an orientation computed according to the given local to fixed frame converter.
*
* For the localFrameToFixedFrame parameter, Cesium provides the following:
*
* Cesium.Transforms.eastNorthUpToFixedFrame
* Cesium.Transforms.northEastDownToFixedFrame
* Cesium.Transforms.northUpEastToFixedFrame
* Cesium.Transforms.northWestUpToFixedFrame
*
* Additionally, argon.js provides:
*
* Argon.eastUpSouthToFixedFrame
*
* Alternative transform functions can be created with:
*
* Cesium.Transforms.localFrameToFixedFrameGenerator
*/
public createGeoEntity(cartographic: Cartographic, localFrameToFixedFrame: typeof Transforms.northUpEastToFixedFrame) : Entity {
// Convert the cartographic location to an ECEF position
var position = Cartesian3.fromDegrees(cartographic.longitude, cartographic.latitude, cartographic.height, undefined, this._scratchCartesian);

// compute an appropriate orientation on the surface of the earth
var transformMatrix = localFrameToFixedFrame(position, undefined, this._scratchMatrix4);
var rotationMatrix = Matrix4.getRotation(transformMatrix,this._scratchMatrix3)
var orientation = Quaternion.fromRotationMatrix(rotationMatrix, this._scratchQuaternion);

// create the entity
var entity = new Entity({
position,
orientation
});
return entity;
}

/**
* Create a new EntityPose instance to represent the pose of an entity
* relative to a given reference frame. If no reference frame is specified,
Expand Down
9 changes: 8 additions & 1 deletion src/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/// <reference types="cesium" />
import { SerializedEntityState } from './common';
import { Entity, JulianDate, PerspectiveFrustum, PerspectiveOffCenterFrustum, Quaternion, Cartesian3, ReferenceFrame, Matrix4 } from './cesium/cesium-imports';
import { Entity, JulianDate, PerspectiveFrustum, PerspectiveOffCenterFrustum, Quaternion, Cartesian3, ReferenceFrame, Matrix4, Transforms } from './cesium/cesium-imports';
export * from './utils/command-queue';
export * from './utils/event';
export * from './utils/message-channel';
export { default as getEventSynthesizier } from './utils/ui-event-synthesizer';
export { default as createEventForwarder } from './utils/ui-event-forwarder';
/**
* Computes a 4x4 transformation matrix from a reference frame with an east-up-south axes centered at the provided origin to the provided ellipsoid's fixed reference frame. The local axes are defined as:
* The x axis points in the local east direction.
* The y axis points in the points in the direction of the ellipsoid surface normal which passes through the position..
* The z axis points in the local south direction.
*/
export declare const eastUpSouthToFixedFrame: Transforms.ConversionFunction;
/**
* Get array of ancestor reference frames of a Cesium Entity, ordered from
* farthest ancestor to the passed frame, excluding the passed frame.
Expand Down
13 changes: 12 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
Quaternion,
Cartesian3,
ReferenceFrame,
Matrix4
Matrix4,
Transforms
} from './cesium/cesium-imports'

export * from './utils/command-queue';
Expand All @@ -21,6 +22,16 @@ export * from './utils/message-channel';
export {default as getEventSynthesizier} from './utils/ui-event-synthesizer';
export {default as createEventForwarder} from './utils/ui-event-forwarder';



/**
* Computes a 4x4 transformation matrix from a reference frame with an east-up-south axes centered at the provided origin to the provided ellipsoid's fixed reference frame. The local axes are defined as:
* The x axis points in the local east direction.
* The y axis points in the points in the direction of the ellipsoid surface normal which passes through the position..
* The z axis points in the local south direction.
*/
export const eastUpSouthToFixedFrame = Transforms.localFrameToFixedFrameGenerator('east','up');

/**
* Get array of ancestor reference frames of a Cesium Entity, ordered from
* farthest ancestor to the passed frame, excluding the passed frame.
Expand Down
2 changes: 2 additions & 0 deletions types/cesium/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4732,6 +4732,8 @@ declare module 'cesium' {
}

module Transforms {
type ConversionFunction = (origin: Cartesian3, ellipsoid?: Ellipsoid, result?: Matrix4) => Matrix4;
function localFrameToFixedFrameGenerator(firstAxis: string, secondAxis: string): ConversionFunction;
function eastNorthUpToFixedFrame(origin: Cartesian3, ellipsoid?: Ellipsoid, result?: Matrix4): Matrix4;
function northEastDownToFixedFrame(origin: Cartesian3, ellipsoid?: Ellipsoid, result?: Matrix4): Matrix4;
function northUpEastToFixedFrame(origin: Cartesian3, ellipsoid?: Ellipsoid, result?: Matrix4): Matrix4;
Expand Down

0 comments on commit 00c5f3f

Please sign in to comment.