From ac1d14217c62c8b968c12993462ae923bfceb162 Mon Sep 17 00:00:00 2001 From: Daniel Cheung Date: Mon, 18 Mar 2019 18:16:37 +0800 Subject: [PATCH 1/2] Added 3 pt lighting --- MyModel.cpp | 27 ++++++++++++++++++++++++++- main.cpp | 1 + modelerglobals.h | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/MyModel.cpp b/MyModel.cpp index 8e420db..b7df0fb 100644 --- a/MyModel.cpp +++ b/MyModel.cpp @@ -116,6 +116,23 @@ void MyModel::draw() lightPosition0[3] = 1; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0); + if (VAL(LIGHT_3_PT)) + { + glEnable(GL_LIGHT2); + GLfloat lightPos0[] = { -26.8f, 30.f, 8.f, 1.f }; + GLfloat lightPos1[] = { 14.5f, 0.8f, 15.5f, 1.f }; + GLfloat lightPos2[] = { -1.8f, -7.3f, -14.7f, 1.f }; + GLfloat lightIntensity0[] = { 1.f, 1.f, 1.f, 1.f }; + GLfloat lightIntensity1[] = { 0.5f, 0.5f, 0.5f, 0.f }; + GLfloat lightIntensity2[] = { .2f, .2f, .2f, .2f }; + glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); + glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); + glLightfv(GL_LIGHT2, GL_POSITION, lightPos2); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity0); + glLightfv(GL_LIGHT1, GL_DIFFUSE, lightIntensity1); + glLightfv(GL_LIGHT2, GL_DIFFUSE, lightIntensity2); + } + // draw the floor setAmbientColor(.1f, .1f, .1f); setDiffuseColor(COLOR_RED); @@ -127,7 +144,15 @@ void MyModel::draw() glPushMatrix(); setDiffuseColor(0.5f, 0.9f, 0.9f); glTranslated(-4, 0.001, -4); - drawLathe({ {0.0, 1.0}, {1.0, 2.0}, {1.2, 2}, {0.1, 0.9}, {0.1, 0.1}, {1.0, 0.0}, {0.0, 0.0} }); + drawLathe({ {0.0, 1.0}, {1.0, 2.0}, {1.2, 2}, {0.1, 0.9}, {0.1, 0.1}, {1.0, 0.0}, {0.0, 0.0} }); //martini + glPopMatrix(); + + glPushMatrix(); + setDiffuseColor(0.5f, 0.9f, 0.9f); + glTranslated(-4, 0.001, -1); + drawLathe({ {0, 0.96}, {0.5, 1}, {0.84, 1.3}, {0.83, 1.84}, {0.5, 2.6}, {0.6, 2.6}, {0.94, 1.84}, {0.94, 1.25}, {0.54, 0.91}, {0.1, 0.86}, {0.1, 0.1}, {1, 0}, {0,0} }); //wine glass + setDiffuseColor(0.4f, 0.f, 0.f); + drawLathe({ {0, 0.96}, {0.5, 1}, {0.84, 1.3}, {0.83, 1.84}, {0, 1.84}}); glPopMatrix(); // draw ik target point diff --git a/main.cpp b/main.cpp index fb05f4b..11d253a 100644 --- a/main.cpp +++ b/main.cpp @@ -51,6 +51,7 @@ int main() controls[LIGHTX] = ModelerControl("Light X", -30, 30, 0.1, -20); controls[LIGHTY] = ModelerControl("Light Y", -30, 30, 0.1, 12); controls[LIGHTZ] = ModelerControl("Light Z", -30, 30, 0.1, 20); + controls[LIGHT_3_PT] = ModelerControl("Enable 3 Point Lighting", 0, 1, 1, 0); controls[LEVELDETAILS] = ModelerControl("Level of Details", 0, 10, 1, 10); controls[ENABLEANIM] = ModelerControl("Enable Anim", 0, 1, 1, 0); controls[CYCLINGMOOD] = ModelerControl("Cycling Mood", 0, 2, 1, 0); diff --git a/modelerglobals.h b/modelerglobals.h index 15d61b0..bf66520 100644 --- a/modelerglobals.h +++ b/modelerglobals.h @@ -15,7 +15,7 @@ enum SampleModelControls { XPOS, YPOS, ZPOS, HEIGHT, ROTATE, ARM1V, ARM1H, ARM2V, ARM2H, ARM3V, ARM3H, CLAMPWIDTH, - LIGHTX, LIGHTY, LIGHTZ, LEVELDETAILS, + LIGHTX, LIGHTY, LIGHTZ, LIGHT_3_PT, LEVELDETAILS, ENABLEANIM, CYCLINGMOOD, LDISP, LDEPTH, LANGLE, LLEN, LTHICKNESS, LDECAYTHICKNESS, LDECAYLENGTH, BALLJOINTS, BOXARMS, From 0584da2bb4e8a891c1aa6b5e5f07bc499f5227d4 Mon Sep 17 00:00:00 2001 From: dipsywong98 Date: Tue, 19 Mar 2019 18:06:48 +0800 Subject: [PATCH 2/2] shaking hand is awesome and update readme --- MyModel.cpp | 25 +++++++++++++++---------- main.cpp | 3 ++- modelerglobals.h | 3 ++- readme.md | 4 ++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/MyModel.cpp b/MyModel.cpp index b7df0fb..ad07e4e 100644 --- a/MyModel.cpp +++ b/MyModel.cpp @@ -155,6 +155,10 @@ void MyModel::draw() drawLathe({ {0, 0.96}, {0.5, 1}, {0.84, 1.3}, {0.83, 1.84}, {0, 1.84}}); glPopMatrix(); + if (VAL(SHOWPRISM)) { + drawTest(); + } + // draw ik target point if(VAL(IKENABLE)) { @@ -232,18 +236,19 @@ void MyModel::drawArm(int levels, int curDept) glRotated(VAL(ARM1V + curDept*2)+(mood==1)*moodTick, 0, 1, 0); if (mood == 2) - glTranslated(levels*sin(32 * rad(levels*moodTick)) / 1000.f, 0, levels*cos(32 * rad(levels*moodTick)) / 1000.f); + glTranslated(levels*sin(32 * rad(levels*moodTick)) / 100.f, 0, levels*cos(32 * rad(levels*moodTick)) / 100.f); + //vertical arm cylinder glPushMatrix(); - if(VAL(BOXARMS)==0) - { - glRotated(-90, 1, 0, 0); - drawCylinder(2, 1, 1); - }else - { - glTranslated(-1, 0, -0.5); - drawBox(2, 2, 1); - } + if(VAL(BOXARMS)==0) + { + glRotated(-90, 1, 0, 0); + drawCylinder(2, 1, 1); + }else + { + glTranslated(-1, 0, -0.5); + drawBox(2, 2, 1); + } glPopMatrix(); //joint cylinder diff --git a/main.cpp b/main.cpp index 11d253a..f2c82ca 100644 --- a/main.cpp +++ b/main.cpp @@ -62,7 +62,7 @@ int main() controls[LTHICKNESS] = ModelerControl("Lsystem: thickness", 0.01, 1, 0.01, 0.1); controls[LDECAYTHICKNESS] = ModelerControl("Lsystem: decay thickness", 0.01, 10, 0.01, 1); controls[LDECAYLENGTH] = ModelerControl("Lsystem: decay length", 0.01, 10, 0.01, 1); - controls[BALLJOINTS] = ModelerControl("Ball joints", 0, 1,1, 0); + controls[BALLJOINTS] = ModelerControl("Ball joints", 0, 1,1, 1); controls[BOXARMS] = ModelerControl("Box Arms", 0, 1,1, 0); controls[IKENABLE] = ModelerControl("IK: enable", 0, 1,1, 0); controls[IKX] = ModelerControl("IK: X", -10, 10,0.01, 3); @@ -70,6 +70,7 @@ int main() controls[IKZ] = ModelerControl("IK: Z", -10, 10,0.01, 3); controls[IKMIN] = ModelerControl("IK: Min", -180, 180,1, -90); controls[IKMAX] = ModelerControl("IK: Max", -180, 180,1, 90); + controls[SHOWPRISM] = ModelerControl("Show Prism", 0, 1, 1, 0); ModelerApplication::Instance()->Init(&createSampleModel, controls, NUMCONTROLS); return ModelerApplication::Instance()->Run(); diff --git a/modelerglobals.h b/modelerglobals.h index bf66520..1a0350e 100644 --- a/modelerglobals.h +++ b/modelerglobals.h @@ -19,7 +19,8 @@ enum SampleModelControls ENABLEANIM, CYCLINGMOOD, LDISP, LDEPTH, LANGLE, LLEN, LTHICKNESS, LDECAYTHICKNESS, LDECAYLENGTH, BALLJOINTS, BOXARMS, - IKENABLE, IKX, IKY, IKZ, IKMIN, IKMAX, NUMCONTROLS + IKENABLE, IKX, IKY, IKZ, IKMIN, IKMAX, + SHOWPRISM, NUMCONTROLS }; // Colors diff --git a/readme.md b/readme.md index 7d978a0..6add802 100644 --- a/readme.md +++ b/readme.md @@ -24,9 +24,9 @@ B: Bell, W: Whistle, 1B=2W - [x] (1B) Widget to control param and create individual-looking instances - [x] **(1B)** Fit whole model in camera (Frame All) - [x] (1B1W) an intuitive way for the user to twist the camera via mouse control. -- [ ] *(2B)* New primitives (is it 2B for each) +- [x] *(2B)* New primitives (is it 2B for each) - [ ] 1. Given Curve A and B, surface form by sweep A through B - - [ ] 2. Given Curve A and stright line L, surface form by rotate A about L + - [x] 2. Given Curve A and stright line L, surface form by rotate A about L - [ ] 3. Torus 4. Others base on coolness - [x] (2B) procedural modelling with parameter control [L-system](https://en.wikipedia.org/wiki/L-system)