Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

take 2 #3

Merged
merged 5 commits into from Oct 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
7 changes: 5 additions & 2 deletions include/Cloth.h
Expand Up @@ -29,7 +29,7 @@
#include "cinder/Frustum.h"

#include "cinder/Camera.h"

using namespace ci;
using namespace cinder;

Expand All @@ -55,7 +55,7 @@ class Cloth

void Init(float angle = 50.0f);
void Shutdown();
void Update( CameraPersp& cullCam);
void Update( );
void Render();
void BuildMesh(btSoftBody* b);
void AddBody();
Expand All @@ -81,6 +81,9 @@ class Cloth
float mTime;
AxisAlignedBox3f mObjectBoundingBox;
bool currentlyculled;

ci::CameraPersp mCamera;

protected:
//! singleton instance
static Cloth *s_Cloth;
Expand Down
17 changes: 16 additions & 1 deletion include/MindField.h
Expand Up @@ -5,7 +5,7 @@
// Created by Shalin Shodhan on 10/6/12.
//
//

#ifndef __PixarDemo2012__Neuron__
#define __PixarDemo2012__Neuron__

Expand All @@ -17,6 +17,10 @@
#include "cinder/gl/Texture.h"
#include "cinder/gl/GlslProg.h"

#include "cinder/Camera.h"

#include "cinder/gl/Fbo.h"

#include <iostream>
#include <vector>
#include <map>
Expand Down Expand Up @@ -165,6 +169,17 @@ class MindField {
const char* mAxonVert;
const char* mAxonFrag;

//fbo
gl::Fbo mSourceFBO;
gl::Fbo mBlur1FBO;
gl::Fbo mBlur2FBO;
gl::Fbo mDepthFBO;

ci::CameraPersp mCamera;

Vec3f mNextCamPoint;
float mLerper;

protected:
//! singleton instance
static MindField *s_MindField;
Expand Down
74 changes: 52 additions & 22 deletions src/Cloth.cpp
Expand Up @@ -16,7 +16,7 @@ using namespace ci;
using namespace std;
using namespace ci::app;
Cloth *Cloth::s_Cloth= 0;

Cloth::Cloth()
{

Expand All @@ -31,6 +31,9 @@ Cloth::~Cloth()

void Cloth::Init(float angle)
{
mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.1f, 1000.0f );
mCamera.lookAt( Vec3f( 0.0f, 0.0f, -10.0f ), Vec3f::zero() );

currentlyculled = true;
mTime = 0.0;
collisionConfig=new btSoftBodyRigidBodyCollisionConfiguration();
Expand All @@ -43,7 +46,8 @@ void Cloth::Init(float angle)

AddBody();

//btTransform t;

//btTransform t;
//t.setIdentity();
//t.setOrigin(btVector3(0,0,0));

Expand All @@ -54,8 +58,8 @@ void Cloth::AddBody()
float s=8;
float t = 16;
float h= 6;
int res_x = 30;
int res_y = 30;
int res_x = 60;
int res_y = 60;
tex_coords = new float[ (res_x - 1)*(res_y -1)*12 ];
btSoftBody* softBody=btSoftBodyHelpers::CreatePatchUV(
world->getWorldInfo(),btVector3(-s,h,-t),btVector3(s,h,-t),
Expand All @@ -67,30 +71,24 @@ void Cloth::AddBody()

softBody->m_cfg.kLF = 0.05;
softBody->m_cfg.kDG = 0.006;
softBody->m_cfg.aeromodel = btSoftBody::eAeroModel::V_TwoSidedLiftDrag;
softBody->m_cfg.aeromodel = btSoftBody::eAeroModel::V_TwoSidedLiftDrag;



// softBody->setWindVelocity(btVector3((randFloat() *2.0 - 1.0)* 10.0f, (randFloat()*2.0 - 1.0)* 4.0f, (randFloat()*2.0 - 1.0)* 5.0f));
//softBody->setMass(100,100);


//softBody->getCollisionShape()->setMargin(0.5);

btSoftBody::Material* pm=softBody->appendMaterial();
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
softBody->m_materials[0]->m_kLST = 0.4;

// softBody->getCollisionShape()->setMargin(0.01);

softBody->m_cfg.collisions |= btSoftBody::fCollision::VF_SS;
softBody->m_cfg.collisions |= btSoftBody::fCollision::CL_SELF;

/* softBody->appendLink(0,1);
softBody->appendLink(1,2);
softBody->appendLink(2,3);
softBody->appendLink(3,0);
softBody->appendLink(0,2);*/
// softBody->randomizeConstraints();
// softBody->generateClusters(1);
// softBody->randomizeConstraints();
// softBody->generateClusters(16);

softBody->generateBendingConstraints(2,pm);

Expand All @@ -101,6 +99,18 @@ void Cloth::AddBody()
// softBody->addForce(btVector3(0,2,0),0);
// softBody->setWindVelocity(btVector3(1,3,-1));

//softBody->m_cfg.piterations=1;
//psb->generateClusters(128);
// softBody->generateClusters(16);
//psb->getCollisionShape()->setMargin(0.5);


//softBody->m_cfg.collisions = btSoftBody::fCollision::CL_SS+ btSoftBody::fCollision::CL_RS
//+ btSoftBody::fCollision::CL_SELF
//;
//softBody->m_materials[0]->m_kLST=0.8;


ResetTransform(softBody);

world->addSoftBody(softBody); //cloth
Expand All @@ -109,14 +119,19 @@ void Cloth::AddBody()

void Cloth::PreRoll()
{

for(int i = 0; i < 100; i ++)
{
world->stepSimulation(1/60.0);
}

}
void Cloth::ResetTransform(btSoftBody* b)
{
btTransform trs;
// btQuaternion rot;
btVector3 pos = btVector3(5, 10, 8);
// btVector3 pos = btVector3(5, 3, 0);
//rot.setRotation(btVector3(1, 0, 0), btScalar(SIMD_PI/2));
trs.setIdentity();
trs.setOrigin(pos);
Expand Down Expand Up @@ -174,21 +189,26 @@ void Cloth::BuildMesh(btSoftBody* b)
}


void Cloth::Update( CameraPersp& cullCam)


void Cloth::Update( )
{
mTime = mTime + getFrameRate()/60.0f;



world->stepSimulation(1/60.0);
for(int i=0;i<world->getSoftBodyArray().size();i++)
{

btSoftBody* b = world->getSoftBodyArray()[i];
BuildMesh(b);
// BuildMesh(b);

float xW = 0.23 * cos(mTime*0.02 );
float yW = 0.5 * sin(mTime * 0.04 );
float zW = 0.15* sin(mTime*0.01);
b->setWindVelocity(btVector3(xW, yW, zW));
//b->setWindVelocity(btVector3(1.3, 3.9, 1.1));
/*
for(int i=0;i<b->m_faces.size();i++)
{
Expand All @@ -197,11 +217,15 @@ void Cloth::Update( CameraPersp& cullCam)
}
*/
// b->addForce(btVector3(xW, yW, zW));
Vec3f camPos = cullCam.getCenterOfInterestPoint();


Vec3f camPos = mCamera.getCenterOfInterestPoint();
Vec3f ps = mObjectBoundingBox.getCenter();
camPos+=(ps-camPos)*0.05;
cullCam.setEyePoint( camPos + ((sin(mTime*0.001) *0.5+0.5) +0.5)* 15.0 * Vec3f(0.0,0.8,-1.0));
cullCam.setCenterOfInterestPoint( camPos);
mCamera.setEyePoint( camPos + ((sin(mTime*0.001) *0.5+0.5) +0.5)* 15.0 * Vec3f(0.0,0.8,-1.0));
mCamera.setCenterOfInterestPoint( camPos);


/*
//! perform frustum culling **********************************************************************************
Frustumf visibleWorld( cullCam );
Expand Down Expand Up @@ -240,8 +264,13 @@ void Cloth::Render()
// gl::enable(GL_CULL_FACE);
// glCullFace(GL_BACK);
// gl::disableAlphaTest();

//gl::enableAlphaBlending();
gl::setMatrices( mCamera );
for(int i=0;i<world->getSoftBodyArray().size();i++)
{
btSoftBody* b = world->getSoftBodyArray()[i];
BuildMesh(b);
if( mMesh.getNumTriangles() ) {
mClothShader.bind();
float what = mTime;
Expand All @@ -251,6 +280,7 @@ void Cloth::Render()
mClothShader.unbind();
}
}
gl::popMatrices();
}

void Cloth::Shutdown()
Expand All @@ -273,8 +303,8 @@ void Cloth::bindShaders()
{

//string mPath = getResourcePath().generic_string();
string mPath = "/Users/colin/Dev/cinder_projects/PixarDemo2012/resources";
// string mPath = "/Users/shalinkhyati/PixarDemo2012/resources";
//string mPath = "/Users/colin/Dev/cinder_projects/PixarDemo2012/resources";
string mPath = "/Users/shalinkhyati/PixarDemo2012/resources";
string nv = mPath + "/cloth.vert";
string nf = mPath + "/cloth.frag";
mClothVert = nv.c_str();
Expand Down
71 changes: 69 additions & 2 deletions src/MindField.cpp
Expand Up @@ -12,14 +12,15 @@
#include "cinder/Utilities.h"
#include "cinder/Rand.h"

#include "cinder/Camera.h"
#include "Resources.h"

using namespace ci::app;
using namespace std;

MindField *MindField::s_MindField= 0;
//////////////////////////////////////////////////////////////////////////////////////////// Neuron START

Neuron::Neuron()
{

Expand Down Expand Up @@ -247,6 +248,12 @@ MindField::~MindField()

void MindField::Init()
{
mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.1f, 1000.0f );
mCamera.lookAt( Vec3f( 0.0f, 0.0f, -10.0f ), Vec3f::zero() );

mNextCamPoint = mNextCamPoint = Vec3f(randFloat(-10,10), randFloat(-10,10), randFloat(-10,10));
mLerper = 0.0f;

kBXDiv = (kXHigh - kXLow)/ kBX;
kBYDiv = (kYHigh - kYLow)/ kBY;
kBZDiv = (kZHigh - kZLow)/ kBZ;
Expand All @@ -260,11 +267,24 @@ void MindField::Init()
}

UpdateAxons();

gl::Fbo::Format format;
mSourceFBO = gl::Fbo( getWindowWidth(), getWindowHeight(), format);
mBlur1FBO = gl::Fbo( getWindowWidth()/2, getWindowHeight()/2, format);
mBlur2FBO = gl::Fbo( getWindowWidth()/2, getWindowHeight()/2, format);
mDepthFBO = gl::Fbo( getWindowWidth(), getWindowHeight(), format);



}

void MindField::Shutdown()
{
mSourceFBO.reset();
mBlur1FBO.reset();
mBlur2FBO.reset();
mDepthFBO.reset();

for(int i = 0; i < mNeurons.size(); i++)
{
mNeurons[i]->Shutdown();
Expand All @@ -287,6 +307,15 @@ void MindField::Shutdown()

void MindField::Render()
{
mSourceFBO.bindFramebuffer();

gl::setViewport( mSourceFBO.getBounds() );

gl::setMatricesWindow( getWindowSize(), true );
gl::setMatrices( mCamera );

glClear(GL_DEPTH_BUFFER_BIT);
gl::clear( ColorA(0.2f,0.2f,0.2f,1.0f) );

// bind neuron shaders
mNeuronShader.bind();
Expand All @@ -303,6 +332,20 @@ void MindField::Render()
(*p)->Render();
}
mAxonShader.unbind();

mSourceFBO.unbindFramebuffer();

gl::popMatrices();


// draw FBO bg
gl::setMatricesWindow( getWindowSize(), true );
gl::color(1.0f,1.0f,1.0f);
gl::draw( mSourceFBO.getTexture(0), Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
// gl::draw( mSourceFBO.getDepthTexture(), Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
// reset camera for geometry
gl::popMatrices();

}

void MindField::UpdateAxons()
Expand Down Expand Up @@ -467,6 +510,29 @@ void MindField::ClearBins()

void MindField::Update()
{

//camera update
Vec3f pos = mCamera.getEyePoint();

Vec3f newPos = pos.lerp(mLerper, mNextCamPoint);
mCamera.setEyePoint(newPos);
mCamera.setCenterOfInterestPoint(Vec3f(0,0,0));

mLerper = mLerper + 0.0000001* getFrameRate();
if(mLerper >= 1.0)
{
mLerper = 0.0;
mNextCamPoint = Vec3f(randFloat(-10,10), randFloat(-10,10), randFloat(-10,10));
}

if(pos.distance(mNextCamPoint) < 5)
{
mLerper = 0.0;
mNextCamPoint = Vec3f(randFloat(-10,10), randFloat(-10,10), randFloat(-10,10));
}
// end camera update


for(int i = 0; i < mNeurons.size(); i++)
{
Neuron* n = mNeurons[i];
Expand Down Expand Up @@ -531,7 +597,8 @@ void MindField::bindShaders()
{

//string mPath = getResourcePath().generic_string();
string mPath = "/Users/colin/Dev/cinder_projects/PixarDemo2012/resources";
// string mPath = "/Users/colin/Dev/cinder_projects/PixarDemo2012/resources";
string mPath = "/Users/shalinkhyati/PixarDemo2012/resources";
string nv = mPath + "/neuron.vert";
string nf = mPath + "/neuron.frag";
mNeuronVert = nv.c_str();
Expand Down