Skip to content

Instantly share code, notes, and snippets.

View terryjsmith's full-sized avatar

Terry Smith terryjsmith

View GitHub Profile
Frustum Camera::CalculateFrustum(float fnear, float ffar) {
Frustum returnFrustum;
// Calculate the near and far plane points
float nearHeight = 2 * tan(fov / 2) * fnear;
float nearWidth = nearHeight * aspect;
float farHeight = 2 * tan(fov / 2) * ffar;
float farWidth = farHeight * aspect;
// And their centers
void ScriptSystem::Update(float delta) {
// Global updates
ScriptTime::SetDelta(delta);
for(int i = 0; i < m_scriptablePoolSize; i++) {
if(m_scriptables[i]) {
// Set global script variables
m_currentObject = m_scriptables[i];
Entity* obj = m_currentObject->GetParent();
MeshInstance* instance = (MeshInstance*)obj->FindComponent<MeshInstance>();
void Script::Initialize(char* src) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
// Create a stack-allocated handle scope.
v8::HandleScope handle_scope(isolate);
// Create an instance of the global context so we can plug variables in
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
float ScriptTime::m_delta = 0;
ScriptTime::ScriptTime() {
m_delta = 0;
}
ScriptTime::~ScriptTime() {
}
/**
* Getter and setter functions for our classes to V8
*/
typedef v8::Local<v8::Value> (*ScriptGlobalGetterFunc)(v8::Isolate*);
/**
* A storage for getter and setter to variable pairs
*/
class ScriptGlobalCallbackPair {
public:
/**
* A helper class that other types can be inherited from (handles basic V8 integration)
*/
class ScriptObject {
public:
ScriptObject();
~ScriptObject();
/**
* Unwrap a v8::object back into a C++ object
ScriptVector3::ScriptVector3() {
m_vector.x = m_vector.y = m_vector.z = 0.0f;
}
ScriptVector3::ScriptVector3(const v8::FunctionCallbackInfo<v8::Value>& info) {
float x, y, z;
x = y = z = 0.0f;
if(info.Length() == 1) {
assert(info[0]->IsNumber());
//
// scripttype.hpp
// eternity
//
// Created by Terry Smith on 2016-09-13.
// Copyright © 2016 Terry Smith. All rights reserved.
//
#ifndef scripttype_hpp
#define scripttype_hpp
Script::Script() {
}
Script::~Script() {
}
void Script::Initialize(char* src) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
#include <eternity.hpp>
ScriptSystem::ScriptSystem() {
m_platform = 0;
m_isolate = 0;
m_scriptableCount = 0;
m_scriptablePoolSize = 0;
m_scriptables = 0;
}