我是一个完全的初学者,所以如果我问这个问题可能很愚蠢或不合适,请原谅我。我正在尝试制作自己的虚拟示波器。我真的不知道如何解释它,但我想从我得到波形峰值的地方“缩小”,这是窗口大小。我不确定我在这里做错了什么,也不知道我的代码有什么问题。我试着改变缓冲区大小,改变x/y的乘数。我的草图改编自一个小型的示例草图。非常感谢所有的帮助。
import ddf.minim.*;
Minim minim;
AudioInput in;
int frames;
int refresh = 7;
float fade = 32;
void setup()
{
size(800, 800, P3D);
minim = new Minim(this);
ellipseMode(RADIUS);
// use the getLineIn method of the Minim object to get an AudioInput
in = minim.getLineIn(Minim.STEREO);
println (in.bufferSize());
//in.enableMonitoring();
frameRate(1000);
background(0);
}
void draw()
{
frames++; //same saying frames = frames+1
if (frames%refresh == 0){
fill (0, 32, 0, fade);
rect (0, 0, width, height);
}
float x;
float y;
stroke (0, 0);
fill (0,255,0);
// draw the waveforms so we can see what we are monitoring
for(int i = 0; i < in.bufferSize() - 1; i++)
{
x = width/2 + in.left.get(i) * height/2;
y = height/2- in.right.get(i) * height/2;
ellipse(x, y, .5, .5);
}
}
谢谢
发布于 2020-12-21 05:11:44
编辑:这里不需要推送和弹出矩阵。我想我对它的理解也是不够的。您可以只使用translate。
你可以使用矩阵来创建一个相机对象,你可以阅读大量的材料来理解背后的数学原理,并在任何地方实现它。
然而,这里可能有一个更简单的解决方案。您可以将pushMatrix和popMatrix与translate结合使用。推送和弹出矩阵将操纵矩阵堆栈-你创建了一个新的“帧”,在那里你可以玩平移,然后弹回原始帧(这样你就不会因为在每帧上应用新的平移而迷失方向)。
按下矩阵,将z坐标平移一次,然后绘制想要缩小的所有内容,弹出矩阵。您可以为转换设置一个变量,以便您可以使用鼠标控制此操作。
下面是一个简单的示例(我没有所有这些库,所以无法将其添加到您的代码中):
float scroll = 0;
float scroll_multiplier = 10;
void setup()
{
size(800, 800, P3D);
frameRate(1000);
background(0);
}
void draw()
{
background(0);
//draw HUD - things that don't zoom.
fill(255,0,0);
rect(400,300,100,100);
//We don't want to mess up our coordinate system, we push a new "frame" on the matrix stack
pushMatrix();
//We can now safely translate the Y axis, creating a zoom effect. In reality, whatever we pass to translate gets added to the coordinates of draw calls.
translate(0,0,scroll);
//Draw zoomed elements
fill(0,255,0);
rect(400,400,100,100);
//Pop the matrix - if we don't push and pop around our translation, the translation will be applied every frame, making our drawables dissapear in the distance.
popMatrix();
}
void mouseWheel(MouseEvent event) {
scroll += scroll_multiplier * event.getCount();
}
https://stackoverflow.com/questions/65384708
复制相似问题