Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I will attach the assaignment below. I also need to complete this code for this assaignment: function render ( ) { gl . clear (

I will attach the assaignment below. I also need to complete this code for this assaignment: function render(){
gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT);
var armShape = shapes.wireCube;
var matStack =[];
//Save view transform
matStack.push(mv);
//Position Shoulder Joint
mv = mult(mv,translate(-2.0,0.0,0.0));
//Shoulder Joint
mv = mult(mv,rotate(shoulder, vec3(0,0,1)));
//Position Upper Arm Cube
mv = mult(mv,translate(1.0,0.0,0.0));
//Scale and Draw Upper Arm
matStack.push(mv);
mv = mult(mv,scale(2.0,0.4,1.0));
gl.uniformMatrix4fv(mvLoc, gl.FALSE, flatten(transpose(mv)));
gl.drawArrays(armShape.type, armShape.start, armShape.size);
//Undo Scale
mv = matStack.pop();
//Position Elbow Joint
mv = mult(mv, translate(1.0,0.0,0.0));
//Elbow Joint
mv = mult(mv, rotate(elbow,vec3(0,0,1)));
//Position Forearm Cube
mv = mult(mv, translate(1,0.0,0.0));
//Scale and Draw Forearm
matStack.push(mv);
mv = mult(mv, scale(2.0,0.4,1.0));
gl.uniformMatrix4fv(mvLoc, gl.FALSE, flatten(transpose(mv)));
gl.drawArrays(armShape.type, armShape.start, armShape.size);
//Undo Scale
mv = matStack.pop();
//Restore mv to initial state
mv = matStack.pop();
}
//----------------------------------------------------------------------------
// Keyboard Event Functions
//----------------------------------------------------------------------------
//This array will hold the pressed or unpressed state of every key
var currentlyPressedKeys =[];
//Store current state of shift key
var shift;
document.onkeydown = function handleKeyDown(event){
currentlyPressedKeys[event.keyCode]= true;
shift = event.shiftKey;
//Get unshifted key character
var c = event.keyCode;
var key = String.fromCharCode(c);
//Place key down detection code here
}
document.onkeyup = function handleKeyUp(event){
currentlyPressedKeys[event.keyCode]= false;
shift = event.shiftKey;
//Get unshifted key character
var c = event.keyCode;
var key = String.fromCharCode(c);
//Place key up detection code here
}
//isPressed(c)
//Utility function to lookup whether a key is pressed
//Only works with unshifted key symbol
// ie: use "E" not "e"
// use "5" not "%"
function isPressed(c)
{
var code = c.charCodeAt(0);
return currentlyPressedKeys[code];
}
//handleKeys(timePassed)
//Continuously called from animate to cause model updates based on
//any keys currently being held down
function handleKeys(timePassed)
{
//Place continuous key actions here - anything that should continue while a key is
//held
//Calculate how much to move based on time since last update
var s =90.0; //rotation speed in degrees per second
var d = s*timePassed; //degrees to rotate on this frame
//Shoulder Updates
if (shift && isPressed("S"))
{
if (shoulder 90) shoulder =(shoulder + d);
else shoulder =90;
}
if (!shift && isPressed("S"))
{
if (shoulder >-90) shoulder =(shoulder - d);
else shoulder =-90;
}
//Elbow Updates
if (shift && isPressed("E"))
{
if (elbow 0) elbow =(elbow + d);
else elbow =0;
}
if (!shift && isPressed("E"))
{
if (elbow >-144) elbow =(elbow - d);
else elbow =-144;
}
} CMPE 360
Fall 2023
Project 8
WebGL
This assignment is due by 23:59 on Sunday, 17 December 2023
Start with robot_arm.html and robot_arm.js from Project08.zip. When
you run robot_arm.html you should see like below default robot arm.
First load the application and see how it works. Try pressing lower and uppercase 'e' to
move the elbow. Try pressing lower and uppercase 's' to move the shoulder
Now, add three fingers and a thumb to the robot. Use matStack.push() and
matStack.pop() to separate the transformations for each digit. Do not attempt to "untransform"
with an inverse rotate, translate or scale.
, Finally, add some code that will make the finger and thumb move apart when 'f' is
pressed and together when 'F' is pressed. The center of rotation should be at the wrist.
You can interact with this sample solution to see how your arm might work. Click on it and
use the keys described above. I have also added some additional controls:
xx : to rotate the arm on the x axis so you can see it from different angles
yY : to rotate the arm on the Y axis so you can see it from different angles
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions