Created
October 25, 2016 04:06
-
-
Save keithjohnston/61164bcf242861c5b09107c41fb7ce48 to your computer and use it in GitHub Desktop.
AtomicSimpleC++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ResourceCache* cache = GetSubsystem<ResourceCache>(); | |
Scene* scene = new Scene(GetContext()); | |
Octree* octree = scene->CreateComponent<Octree>(); | |
Graphics* graphics = GetSubsystem<Graphics>(); | |
Node* cameraNode = scene->CreateChild("Camera"); | |
cameraNode->SetPosition(Vector3(0.0f, 0.0f, -10.0f)); | |
Camera* camera = cameraNode->CreateComponent<Camera>(); | |
camera->SetOrthographic(true); | |
camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE); | |
Texture2D* decalTex = cache->GetResource<Texture2D>("AtomicEditor/editor/images/newproject_2d.png"); | |
Sprite2D* sp = new Sprite2D(GetContext()); | |
sp->SetTexture(decalTex); | |
SharedPtr<Node> spriteNode(scene->CreateChild("StaticSprite2D")); | |
float halfWidth = graphics->GetWidth() * 0.5f * PIXEL_SIZE; | |
float halfHeight = graphics->GetHeight() * 0.5f * PIXEL_SIZE; | |
for (int i=0;i<100;i++) | |
{ | |
StaticSprite2D* staticSprite = spriteNode->CreateComponent<StaticSprite2D>(); | |
spriteNode->SetPosition(Vector3(Random(-halfWidth, halfWidth), Random(-halfHeight, halfHeight), 0.0f)); | |
staticSprite->SetSprite(sp); | |
// Set random color | |
staticSprite->SetColor(Color(Random(1.0f), Random(1.0f), Random(1.0f), 1.0f)); | |
// Set blend mode | |
staticSprite->SetBlendMode(BLEND_ALPHA); | |
} | |
Renderer* renderer = GetSubsystem<Renderer>(); | |
DebugRenderer* debug = scene->CreateComponent<DebugRenderer>(); | |
// Set up a viewport to the Renderer subsystem so that the 3D scene can be seen | |
SharedPtr<Viewport> viewport(new Viewport(GetContext(), scene, cameraNode->GetComponent<Camera>())); | |
renderer->SetViewport(0, viewport); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment