我在OpenGL中实现了一个简单的相机系统.我在投影矩阵下设置了gluPerspective,然后在ModelView矩阵上使用gluLookAt.在此之后我有我的主渲染循环,它检查键盘事件,如果按下任何箭头键,修改角速度和前进速度(我只旋转y轴并移动z(向前)).然后我使用以下代码移动视图(deltaTime是自上一帧渲染以来的时间量,以秒为单位,以便从帧速率分离移动):
//place our camera
newTime = RunTime(); //get the time since app start
deltaTime = newTime - time; //get the time since the last frame was rendered
time = newTime;
glRotatef(view.angularSpeed*deltaTime,0,1,0); //rotate
glTranslatef(0,0,view.forwardSpeed*deltaTime); //move forwards
//draw our vertices
draw();
//swap buffers
Swap_Buffers();
Run Code Online (Sandbox Code Playgroud)
然后代码再次循环.我的绘制算法以a开头,以a glPushMatrix()结束glPopMatrix().
每次调用glRotatef()和glTranslatef()都会在视图方向上向前推动视图向前移动速度.
然而,当我运行代码时,我的对象被绘制在正确的位置,但是当我移动时,运动是通过世界原点的方向(0,0,0 - 面向Z轴)完成的,而不是局部方向(我指向的地方)当我旋转时,旋转大约是(0,0,0),而不是相机的位置.
我最终得到了我的相机绕轨道(0,0,0)的奇怪效果,而不是现场旋转.
我根本没有glLoadIdentity()在循环内的任何地方调用,我确信矩阵模式设置GL_MODELVIEW为整个循环.
另一个奇怪的效果是,如果我glLoadIdentity()在draw(函数内部调用一个调用(在PushMatrix和PopMatrix调用之间,屏幕变黑,无论我在哪里看都找不到我绘制的对象.
有人知道我为了制作这个轨道(0,0,0)而不是当场旋转而搞砸了吗?
对不起,模糊的主题标题; 很难简洁地描述我的问题.
我收集了大量的对象(几千个),定义为......
public class Item
{
public int ID;
public float A;
public float B;
public float C;
public float D;
public float E;
public float F;
public float G;
}
Run Code Online (Sandbox Code Playgroud)
如果我为这些浮点字段中的每一个赋予了乘数,那么找到我的大集合中哪个项目中最大的那些浮点数乘以它们的乘数的最快方法是什么.
例如,我现在有类似......
public Item FindLargest(float aMult, float bMult, float cMult, float dMult, float eMult, float fMult, float gMult)
{
Item largest = null;
float largestTotal = 0f;
foreach(Item item in ItemsCollection)
{
float total = item.A * aMult +
item.B * bMult +
item.C * cMult +
item.D …Run Code Online (Sandbox Code Playgroud) 嗨,我正在开发一个新项目,需要使用Raphael JS和插件Raphael.Freetransform.到目前为止,该插件工作得非常好,非常顺利.但是,通过使用hideHandles()方法,它似乎也禁用任何形式的对象拖动.
这是一个错误还是一个设计选择?一旦隐藏其手柄,是否需要重新启用对元素的拖动?我试过设置.为了在不使用Freetransform插件的情况下使元素可拖动,我还需要做些什么吗?
这是我的代码:
paper = new Raphael("container", "1680", "1005");
setA = paper.set();
circle = paper.circle(50, 50, 50);
circle.attr("fill", "#f00");
circle.attr("stroke", "#000");
notif = paper.circle(50, 50, 50);
notif.attr({ "fill": "r(0.5, 0.5) #fff-#f00", "fill-opacity": 1 });
lbl = paper.text(50, 50, "Label").attr({fill: '#000000'});
setA.push(circle);
setA.push(notif);
setA.push(lbl);
setA.click(function(){
console.log('clicked');
});
setA.hover(
// over //
function (){ console.log('over'); },
// out //
function (){ console.log('out'); }
);
setA.drag(
//onmove
function(){
console.log('object moving');
},
//onstart
function(){
console.log('start drag');
},
//onend
function(){
console.log('end drag');
}
); …Run Code Online (Sandbox Code Playgroud) 关于这个问题,我能够通过unzipa 进行多次分配List[(A,B)]
但是,现在我发现需要在a List[( (A,B),(C,D) )]或a 上进行多次分配List[(A,B,C,D)]
我看到有成对的解压缩和三胞胎的unzip3,但是如何对一对Tuple2OR 进行解构Tuple4以便进行多指派?我将相应调整下面的集合类型,但无论哪一个适用于一步多指派都可以.
// foo can be a List[(A,B,C,D)] OR List[( (A,B),(C,D) )]
val(a,b,c,d) = foo.unzip
Run Code Online (Sandbox Code Playgroud)
这有效,但被黑了
val(a,b,c_d) foo.unzip3 // foo is a List[(A,B,(C,D))]
Run Code Online (Sandbox Code Playgroud)
因为我不得不这样做,c_d._1而且c_d._2我试图通过多分配变量来避免这种情况
我有以下数据框:
foo <- data.frame( abs( cbind(rnorm(3),rnorm(3, mean=.8),rnorm(3, mean=.9),rnorm(3, mean=1))))
colnames(foo) <- c("w","x","y","z")
rownames(foo) <- c("n","q","r")
foo
# w x y z
# n 1.51550092 1.4337572 1.2791624 1.1771230
# q 0.09977303 0.8173761 1.6123402 0.1510737
# r 1.17083866 1.2469347 0.8712135 0.8488029
Run Code Online (Sandbox Code Playgroud)
我想要做的是将其改为:
newdf
# 1 n w 1.51550092
# 2 q w 0.09977303
# 3 r w 1.17083866
# 4 n x 1.43375725
# 5 q x 0.81737606
# 6 r x 1.24693468
# 7 n y 1.27916241
# 8 q y …Run Code Online (Sandbox Code Playgroud) 我尝试从中心而不是边缘旋转3D立方体.这是我使用的代码.
public rotatemyCube()
{
...
Matrix newTransform = Matrix.CreateScale(scale) * Matrix.CreateRotationY(rotationLoot) * Matrix.CreateTranslation(translation);
my3Dcube.Transform = newTransform;
....
public void updateRotateCube()
{
rotationLoot += 0.01f;
}
Run Code Online (Sandbox Code Playgroud)
我的立方体旋转很好,但不是从中心旋转.这是一个解释我的问题的示意图.

我需要这个:

我的完整代码
private void updateMatriceCubeToRotate()
{
foreach (List<instancedModel> ListInstance in listStructureInstance)
{
foreach (instancedModel instanceLoot in ListInstance)
{
if (my3Dcube.IsAloot)
{
Vector3 scale;
Quaternion rotation;
Vector3 translation;
//I get the position, rotation, scale of my cube
my3Dcube.Transform.Decompose(out scale,out rotation,out translation);
var rotationCenter = new Vector3(0.1f, 0.1f, 0.1f);
//Create new transformation with new rotation
Matrix …Run Code Online (Sandbox Code Playgroud) 我在向量<vector <double >>中有数值数据,需要为它们添加标量值,如下所示:
vector <vector<double> > data ( M, vector<double>(N) );
vector <double>scalars(N);
data[0][0] += scalars[0];
data[0][1] += scalars[1];
...
data[0][N-1] += scalars[N-1];
data[1][0] += scalars[0];
data[1][1] += scalars[1];
...
data[1][N-1] += scalars[N-1];
...
data[M-1][N-1] += scalars[N-1];
Run Code Online (Sandbox Code Playgroud)
当然,这可以通过两个for循环来实现.我想知道它是否可以简单地使用transform,bind和plus来完成?我试图尽可能使用仿函数(尽管仍然习惯使用旧的C风格代码).
内部循环需要对数据中的向量0执行此操作:
transform ( data[0].begin(), data[0].end(),
scalars[0].begin(),
data[0].begin(),
plus<double>() )
Run Code Online (Sandbox Code Playgroud)
是否有可能将此行中的数据[0]替换为另一个计数器(与数据[0] ...数据[N-1]的变换相关)?这可能是一个标准问题,但我找不到一个好的参考.
我正在尝试制作一个简单的"链接云",一些5或6个链接随机分布,绝对定位.当悬停时,它们会(从对象的中心,而不是从左上角)缩放到更大的尺寸,在缩小时缩小.
使用CSS3转换和转换是完全可行的,但我需要一个也适用于IE8 +的解决方案.我的网站的目标受众是使用开箱即用的任何人,因此IE打扰.
我愿意接受任何建议.Javascript,Jquery,Mootools,Prototype ......给它起名,我会试一试.
internet-explorer transition transform css3 internet-explorer-8
我创建了mainView objcet UIView并在其上添加了一个子视图.我在mainView上应用了变换以减小帧大小.但是mainView的子视图框架没有减少.如何减小这个子视图的大小.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGFloat widthM=1200.0;
CGFloat heightM=1800.0;
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, widthM, heightM)];
mainView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"te.png"]];
[self.view addSubview:mainView];
CGFloat yourDesiredWidth = 250.0;
CGFloat yourDesiredHeight = yourDesiredWidth *heightM/widthM;
CGAffineTransform scalingTransform;
scalingTransform = CGAffineTransformMakeScale(yourDesiredWidth/mainView.frame.size.width, yourDesiredHeight/mainView.frame.size.height);
mainView.transform = scalingTransform;
mainView.center = self.view.center;
NSLog(@"mainView:%@",mainView);
UIView *subMainView= [[UIView alloc] initWithFrame:CGRectMake(100, 100, 1000, 1200)];
subMainView.backgroundColor = [UIColor redColor];
[mainView addSubview:subMainView];
NSLog(@"subMainView:%@",subMainView);
} …Run Code Online (Sandbox Code Playgroud) img{
transition-duration: 5s;
transform: scale(1.0);
transform-origin: 50% 50%;
}
&:hover{
img{
transform: scale(1.2);
transform-origin: 50% 50%;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我用于图像中的ken burn效果的代码,它在ff,chrome和safari中工作得非常好.但我不知道11号是什么问题.
你能帮帮我吗?