forked from shks/ofkTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofkModelRender.cpp
executable file
·95 lines (75 loc) · 2.26 KB
/
ofkModelRender.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// ofkModelRender.coo.cpp
// tool class for loading and rendering model
//
// Created by Shunichi Kasahara on 12/03/04.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include "ofkModelRender.h"
ofkModelRender::ofkModelRender()
{
}
void ofkModelRender::init(string assetFilePath)
{
// we need GL_TEXTURE_2D for our models coords.
ofDisableArbTex();
if(model.loadModel(assetFilePath,true)){
model.setAnimation(0);
model.setPosition(ofGetWidth()/2, (float)ofGetHeight() * 0.75 , 0);
//model.createLightsFromAiModel();
//model.disableTextures();
//model.disableMaterials();
mesh = model.getMesh(0);
position = model.getPosition();
normScale = model.getNormalizedScale();
scale = model.getScale();
sceneCenter = model.getSceneCenter();
material = model.getMaterialForMesh(0);
tex = model.getTextureForMesh(0);
}
//some model / light stuff
//glShadeModel(GL_SMOOTH);
bAnimate = true;
bAnimateMouse = false;
animationTime = 0.0;
}
void ofkModelRender::update()
{
//this is for animation if the model has it.
if( bAnimate ){
animationTime += ofGetLastFrameTime();
if( animationTime >= 1.0 ){
animationTime = 0.0;
}
model.setNormalizedTime(animationTime);
mesh = model.getCurrentAnimatedMesh(0);
}
if( bAnimateMouse ){
model.setNormalizedTime(animationTime);
mesh = model.getCurrentAnimatedMesh(0);
}
}
void ofkModelRender::render()
{
//ofPushStyle();
ofSetColor(255, 255, 255, 255);
//note we have to enable depth buffer in main.mm
//see: window->enableDepthBuffer(); in main.mm
//ofEnableBlendMode(OF_BLENDMODE_ADD);
glShadeModel(GL_SMOOTH);
//light.enable();
ofEnableSeparateSpecularLight();
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glScalef(0.005, 0.005, 0.005);
ofPoint vec = model.getPosition();
glTranslatef(-vec.x, -vec.y, -vec.z);
model.drawFaces();
glPopMatrix();
/*
ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
ofDrawBitmapString("fingers 2-5 load models", 10, 30);
ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 45);
*/
//ofPopStyle();
}