如何渲染.obj文件(在3d中)?我该如何为它添加颜色?我在OS X上,并使用XCode 4.这是我的小'测试实验室'.
#include <GLUT/glut.h>
#include <iostream>
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char ** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("Simple GLUT Application");
glutDisplayFunc(render);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
void keyboard(unsigned char c, int x, int y) {
if (c == 27){
exit(0);
}
}
void mouse(int button, int state, int x, int y) {
if (button …Run Code Online (Sandbox Code Playgroud) 我有一个快速的效率问题.
假设我有一个经常被设置为YES的布尔值(当玩家在地面时).
检查BOOL的值是否更有效率,即
if (!character.isOnGround) character.isOnGround = YES;
或者将值设置为YES会更高效,即
character.isOnGround = YES
基本上,问题是这个.if语句比赋值更快吗?
我有这个代码:
public void onPlayerInteract(PlayerInteractEvent event) {
final Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK){
Location l1 = event.getClickedBlock().getLocation();
} else if (action == Action.RIGHT_CLICK_BLOCK) {
Location l2 = event.getClickedBlock().getLocation();
}
Thread t = new Thread() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(1000*60*60);
//Insert code here
} catch (InterruptedException ie) {
}
}
}
};
t.start();
Run Code Online (Sandbox Code Playgroud)
如何访问l1的//insert code here?
我有这个代码:
public void onPlayerInteract(PlayerInteractEvent event) {
final Action action = event.getAction();
Location l1 = null;
Location l2 = null;
if (action == Action.LEFT_CLICK_BLOCK){
l1 = event.getClickedBlock().getLocation();
} else if (action == Action.RIGHT_CLICK_BLOCK) {
l2 = event.getClickedBlock().getLocation();
}
Thread t = new Thread() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(1000*60*60);
Location maxx = l1.getX();
Location maxy = l1.getY();
Location maxz = l1.getZ();
Location minx = l2.getX();
Location miny = l2.getY();
Location minz = l2.getZ();
if(l1.getX() > l2.getX()){ …Run Code Online (Sandbox Code Playgroud) 我正在制作一种语言,每当一个人想要访问变量时,它都带有$符号.但是,在每个函数上我必须有一个if,看看它的第一个字母是否为$,并且每次传递参数时,对于每个参数我都必须这样做.它变得混乱.我想不嵌套if,但有它所以我可以轻松地应用一个函数,并访问它.这有点难以解释,但我会用一些代码来解释.
def varcmd(cmd, variables):
if cmd.__len__() < 4:
print "Too little arguments! str <var> = <string>"
else:
if cmd[2] == "=":
if cmd[3][:1] == "$":
variables[cmd[1]] = variables[cmd[3][1:]]
else:
variables[cmd[1]] = cmd[3]
else:
print "Incorrect syntax! str <var> = <string>"
Run Code Online (Sandbox Code Playgroud)
当我不断添加到这个函数时,if会以指数方式增加,实际上每个函数都可以获取变量,因此每个函数都会有大量的if.基本上,我想要这样的东西:
def varcmd(cmd, variables):
if cmd.__len__() < 4:
print "Too little arguments! str <var> = <string>"
else:
if cmd[2] == "=":
variables[cmd[1]] = auto_convert_if_var.cmd[3][1:]
else:
print "Incorrect syntax! str <var> = <string>"
Run Code Online (Sandbox Code Playgroud)